Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 38787ac

Browse filesBrowse files
TNAJanssenfabpot
authored andcommitted
[Serializer] Fix that it will never reach DOMNode
1 parent cc82746 commit 38787ac
Copy full SHA for 38787ac

File tree

2 files changed

+17
-3
lines changed
Filter options

2 files changed

+17
-3
lines changed

‎src/Symfony/Component/Serializer/Encoder/XmlEncoder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ private function selectNodeType(\DOMNode $node, $val)
488488
$node->appendChild($child);
489489
} elseif ($val instanceof \Traversable) {
490490
$this->buildXml($node, $val);
491+
} elseif ($val instanceof \DOMNode) {
492+
$child = $this->dom->importNode($val, true);
493+
$node->appendChild($child);
491494
} elseif (\is_object($val)) {
492495
if (null === $this->serializer) {
493496
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow "%s()" to be used with object data.', __METHOD__));
@@ -502,9 +505,6 @@ private function selectNodeType(\DOMNode $node, $val)
502505
return $this->appendText($node, $val);
503506
} elseif (\is_bool($val)) {
504507
return $this->appendText($node, (int) $val);
505-
} elseif ($val instanceof \DOMNode) {
506-
$child = $this->dom->importNode($val, true);
507-
$node->appendChild($child);
508508
}
509509

510510
return true;

‎src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,20 @@ public function testEncodeXmlWithBoolValue()
662662
$this->assertEquals($expectedXml, $actualXml);
663663
}
664664

665+
public function testEncodeXmlWithDomNodeValue()
666+
{
667+
$expectedXml = <<<'XML'
668+
<?xml version="1.0"?>
669+
<response><foo>bar</foo><bar>foo &amp; bar</bar></response>
670+
671+
XML;
672+
$document = new \DOMDocument();
673+
674+
$actualXml = $this->encoder->encode(['foo' => $document->createTextNode('bar'), 'bar' => $document->createTextNode('foo & bar')], 'xml');
675+
676+
$this->assertEquals($expectedXml, $actualXml);
677+
}
678+
665679
public function testEncodeXmlWithDateTimeObjectValue()
666680
{
667681
$xmlEncoder = $this->createXmlEncoderWithDateTimeNormalizer();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.