Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 049e641

Browse files
committed
bug #43413 [VarDumper] Fix error with uninitialized XMLReader (villfa)
This PR was merged into the 4.4 branch. Discussion ---------- [VarDumper] Fix error with uninitialized XMLReader | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #42581 | License | MIT | Doc PR | n/a When XMLReader is not initialized, getParserProperty() throws an error (or emits a warning, depending on the PHP version). Now the error is caught and the properties are set to false. <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry --> Commits ------- c97e10c [VarDumper] Fix error with uninitialized XMLReader
2 parents 45a4cef + c97e10c commit 049e641

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/Symfony/Component/VarDumper/Caster/XmlReaderCaster.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ class XmlReaderCaster
4444

4545
public static function castXmlReader(\XMLReader $reader, array $a, Stub $stub, $isNested)
4646
{
47+
try {
48+
$properties = [
49+
'LOADDTD' => @$reader->getParserProperty(\XMLReader::LOADDTD),
50+
'DEFAULTATTRS' => @$reader->getParserProperty(\XMLReader::DEFAULTATTRS),
51+
'VALIDATE' => @$reader->getParserProperty(\XMLReader::VALIDATE),
52+
'SUBST_ENTITIES' => @$reader->getParserProperty(\XMLReader::SUBST_ENTITIES),
53+
];
54+
} catch (\Error $e) {
55+
$properties = [
56+
'LOADDTD' => false,
57+
'DEFAULTATTRS' => false,
58+
'VALIDATE' => false,
59+
'SUBST_ENTITIES' => false,
60+
];
61+
}
62+
4763
$props = Caster::PREFIX_VIRTUAL.'parserProperties';
4864
$info = [
4965
'localName' => $reader->localName,
@@ -57,12 +73,7 @@ public static function castXmlReader(\XMLReader $reader, array $a, Stub $stub, $
5773
'value' => $reader->value,
5874
'namespaceURI' => $reader->namespaceURI,
5975
'baseURI' => $reader->baseURI ? new LinkStub($reader->baseURI) : $reader->baseURI,
60-
$props => [
61-
'LOADDTD' => $reader->getParserProperty(\XMLReader::LOADDTD),
62-
'DEFAULTATTRS' => $reader->getParserProperty(\XMLReader::DEFAULTATTRS),
63-
'VALIDATE' => $reader->getParserProperty(\XMLReader::VALIDATE),
64-
'SUBST_ENTITIES' => $reader->getParserProperty(\XMLReader::SUBST_ENTITIES),
65-
],
76+
$props => $properties,
6677
];
6778

6879
if ($info[$props] = Caster::filter($info[$props], Caster::EXCLUDE_EMPTY, [], $count)) {

src/Symfony/Component/VarDumper/Tests/Caster/XmlReaderCasterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,18 @@ public function provideNodes()
245245
],
246246
];
247247
}
248+
249+
public function testWithUninitializedXMLReader()
250+
{
251+
$this->reader = new \XmlReader();
252+
253+
$expectedDump = <<<'EODUMP'
254+
XMLReader {
255+
+nodeType: NONE
256+
…13
257+
}
258+
EODUMP;
259+
260+
$this->assertDumpMatchesFormat($expectedDump, $this->reader);
261+
}
248262
}

0 commit comments

Comments
 (0)