10000 [Serializer] Ignore comments when decoding XML by q0rban · Pull Request #26445 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Ignore comments when decoding XML #26445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Prev Previous commit
Next Next commit
[Serializer] Add XmlEncoder:: defaults directly to argument, per @ost…
  • Loading branch information
James Sansbury committed Mar 7, 2018
commit b55454e5b52c64ab182f04b9b87cef297d9cadb5
4 changes: 2 additions & 2 deletions src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
* @param int|null $loadOptions A bit field of LIBXML_* constants
* @param int[] $ignoredNodeTypes an array of ignored XML node types, each one of the DOM Predefined XML_* Constants
*/
public function __construct(string $rootNodeName = 'response', int $loadOptions = null, array $ignoredNodeTypes = null)
public function __construct(string $rootNodeName = 'response', int $loadOptions = null, array $ignoredNodeTypes = array(XML_PI_NODE, XML_COMMENT_NODE))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default should be BC -safe, thus XML_COMMENT_NODE should not be listed, isn't it?

Copy link
Contributor
@ostrolucky ostrolucky Mar 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listing XML_COMMENT_NODE is for fixing a bug tho. I don't think anybody relies on old behaviour.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had originally put BC breaks to yes, but it looks like that was changed at some point. Personally, I think comments should be stripped by default, as a comment at the top of the XML to decode ends up becoming the XML root node. See the tests for an example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, can you add an entry in the UPGRADE file when, please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas since this is in the 4.1 milestone, I assume you are referring to the UPGRADE-4.1.md file? If so, I pushed a commit to note the change in this PR.

{
$this->rootNodeName = $rootNodeName;
$this->loadOptions = null !== $loadOptions ? $loadOptions : LIBXML_NONET | LIBXML_NOBLANKS;
$this->ignoredNodeTypes = !empty($ignoredNodeTypes) ? $ignoredNodeTypes : array(XML_PI_NODE, XML_COMMENT_NODE);
$this->ignoredNodeTypes = $ignoredNodeTypes;
}

/**
Expand Down
0