[Serializer] XML ignore="false"
on attribute not respected
#46463
Labels
ignore="false"
on attribute not respected
#46463
Symfony version(s) affected
5.4
Description
The
serializer-mapping-1.0-xsd
includes a booleanignore
attribute on theattribute
element, butignore="false"
is not interpreted asfalse
. The attribute is ignored, because theXMLFileLoader
casts the attribute tobool
, which is always true because it is an instance ofSimpleXMLElement
.How to reproduce
Clone /likeuntomurphy/symfony-serializer-xml-ignore-reproducer and run
docker run --rm -it -v ${PWD}:/app -w /app php:8.1-cli php bin/console serialize-myobject
.The expectation is that the command finishes with no output. However, an assertion fails:
Possible Solution
Use
filter_var((string) $attribute['ignore'], FILTER_VALIDATE_BOOLEAN)
or strictly compare the attribute value against"true"
or"false"
. A quick scan ofvendor
also shows that Doctrine Migrations uses aBooleanStringFormatter
onxsd:boolean
node values.Additional Context
There are no tests for a condition where
ignore="false"
is included — I’m not certain if that is an oversight or if the expectation is that no one will ever do this. This is why I haven’t made a PR.To my mind there should be parity between the schema and the
AttributeMetadata
values.The text was updated successfully, but these errors were encountered: