Skip to content

Commit 45276e3

Browse files
Merge branch '4.4' into 5.4
* 4.4: [Stopwatch] Fix test expectation [SecurityBundle] fix autoconfiguring Monolog's ProcessorInterface KernelTestCase resets internal state on tearDown [HttpKernel] Fix extracting controller name from closures [Intl] fix wrong offset timezone PHP 8.1 Fix type binding Remove duplicated test Make document type nodes ignorable Initialize Symfony\Component\Security\Core\Exception\AccountStatusException:: property
2 parents 45894b0 + e836e2c commit 45276e3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Encoder/XmlEncoder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,13 @@ public function decode(string $data, string $format, array $context = [])
126126
$rootNode = null;
127127
$decoderIgnoredNodeTypes = $context[self::DECODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::DECODER_IGNORED_NODE_TYPES];
128128
foreach ($dom->childNodes as $child) {
129+
if (\in_array($child->nodeType, $decoderIgnoredNodeTypes, true)) {
130+
continue;
131+
}
129132
if (\XML_DOCUMENT_TYPE_NODE === $child->nodeType) {
130133
throw new NotEncodableValueException('Document types are not allowed.');
131134
}
132-
if (!$rootNode && !\in_array($child->nodeType, $decoderIgnoredNodeTypes, true)) {
135+
if (!$rootNode) {
133136
$rootNode = $child;
134137
}
135138
}

Tests/Encoder/XmlEncoderTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,33 @@ public function testDecodeIgnoreComments()
576576
$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
577577
}
578578

579+
public function testDecodeIgnoreDocumentType()
580+
{
581+
$source = <<<'XML'
582+
<?xml version="1.0"?>
583+
<!DOCTYPE people>
584+
<people>
585+
<person>
586+
<firstname>Benjamin</firstname>
587+
<lastname>Alexandre</lastname>
588+
</person>
589+
<person>
590+
<firstname>Damien</firstname>
591+
<lastname>Clay</lastname>
592+
</person>
593+
</people>
594+
XML;
595+
$expected = ['person' => [
596+
['firstname' => 'Benjamin', 'lastname' => 'Alexandre'],
597+
['firstname' => 'Damien', 'lastname' => 'Clay'],
598+
]];
599+
$this->assertEquals($expected, $this->encoder->decode(
600+
$source,
601+
'xml',
602+
[XmlEncoder::DECODER_IGNORED_NODE_TYPES => [\XML_DOCUMENT_TYPE_NODE]]
603+
));
604+
}
605+
579606
public function testDecodePreserveComments()
580607
{
581608
$source = <<<'XML'

0 commit comments

Comments
 (0)