1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-26 20:04:48 +01:00

Fix XML unserializer

The subNodes array was not initialized, so for empty nodes it would just
be null. Due to the addition of attributes for nodes those have to be
initialized too.
This commit is contained in:
nikic 2012-04-04 14:06:08 +02:00
parent e17bd0b17f
commit 337da5648c
2 changed files with 19 additions and 1 deletions

View File

@ -47,7 +47,10 @@ class PHPParser_Unserializer_XML implements PHPParser_Unserializer
// create the node without calling it's constructor
$node = unserialize(
sprintf('O:%d:"%s":0:{}', strlen($className), $className)
sprintf(
"O:%d:\"%s\":2:{s:11:\"\0*\0subNodes\";a:0:{}s:13:\"\0*\0attributes\";a:0:{}}",
strlen($className), $className
)
);
$line = $this->reader->getAttribute('line');

View File

@ -21,6 +21,21 @@ XML;
);
}
public function testEmptyNode() {
$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<AST xmlns:node="http://nikic.github.com/PHPParser/XML/node" xmlns:subNode="http://nikic.github.com/PHPParser/XML/subNode" xmlns:scalar="http://nikic.github.com/PHPParser/XML/scalar">
<node:Scalar_ClassConst />
</AST>
XML;
$unserializer = new PHPParser_Unserializer_XML;
$this->assertEquals(
new PHPParser_Node_Scalar_ClassConst,
$unserializer->unserialize($xml)
);
}
public function testScalars() {
$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>