Skip to content

Commit

Permalink
Merge pull request #270 from mrbig/f/skipping_node_for_foreign_namespace
Browse files Browse the repository at this point in the history
Fixed handling of elements from foreign namespaces in values object (2.2)
  • Loading branch information
phil-davis authored Apr 18, 2024
2 parents 17f1042 + adb731d commit baf08b9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Deserializer/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ function valueObject(Reader $reader, string $className, string $namespace)
// Ignore property
$reader->next();
}
} elseif (Reader::ELEMENT === $reader->nodeType) {
// Skipping element from different namespace
$reader->next();
} else {
if (Reader::END_ELEMENT !== $reader->nodeType && !$reader->read()) {
break;
Expand Down
37 changes: 37 additions & 0 deletions tests/Sabre/Xml/Deserializer/ValueObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,43 @@ public function testDeserializeValueObjectIgnoredElement()
);
}

public function testDeserializeValueObjectIgnoredNamespace()
{
$input = <<<XML
<?xml version="1.0"?>
<foo xmlns="urn:foo" xmlns:alien="urn:example.com">
<firstName>Harry</firstName>
<alien:email>[email protected]</alien:email>
<lastName>Turtle</lastName>
</foo>
XML;

$reader = new Reader();
$reader->xml($input);
$reader->elementMap = [
'{urn:foo}foo' => function (Reader $reader) {
return valueObject($reader, 'Sabre\\Xml\\Deserializer\\TestVo', 'urn:foo');
},
];

$output = $reader->parse();

$vo = new TestVo();
$vo->firstName = 'Harry';
$vo->lastName = 'Turtle';

$expected = [
'name' => '{urn:foo}foo',
'value' => $vo,
'attributes' => [],
];

$this->assertEquals(
$expected,
$output
);
}

public function testDeserializeValueObjectAutoArray()
{
$input = <<<XML
Expand Down

0 comments on commit baf08b9

Please sign in to comment.