-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Open
Description
Symfony version(s) affected
7.4
Description
XmlEncoder::decode()
contains a very old TODO (> 10 years old) about the root node name:
// todo: throw an exception if the root node name is not correctly configured (bc) |
While I wanted to deal with it and directly create a PR, I first want to gather feedback.
- I think there is code missing to catch if
!$rootNode
is true at this point (though the test case I wrote is a bit artificial but the previous loop still allows for it). - At that time, when the TODO was added,
$rootNodeName
already existed thus I assume that the TODO was to throw an exception if the found root node does not match the configured root node name.
At the moment, the root node name is only used for encoding and I am doubt whether a BC break for 8.0 to resolve this TODO and also validate that the root node name matches the configured root node name brings any benefit.
How to reproduce
Look at
// todo: throw an exception if the root node name is not correctly configured (bc) |
Possible Solution
- Add an additional check if
!$rootNode
(Would throw aNotEncodableValueException
instead of generic exception withCall to a member function hasChildNodes() on null
.) (I think that this can be done in 7.4, not only at 8.0?) - Remove the TODO.
- Update documentation https://symfony.com/doc/current/serializer/encoders.html#the-xmlencoder-context-options to mention that the root node name option is only used for encoding.
Additional Context
No response