Skip to content

Commit

Permalink
Merge pull request #273 from phil-davis/f/skipping_node_for_foreign_n…
Browse files Browse the repository at this point in the history
…amespace-master

Fixed handling of elements from foreign namespaces in values object (master)
  • Loading branch information
phil-davis authored Apr 18, 2024
2 parents 3e499be + 775c2a8 commit 8700fd8
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 @@ -223,6 +223,9 @@ function valueObject(Reader $reader, string $className, string $namespace): obje
// 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 @@ -82,6 +82,43 @@ public function testDeserializeValueObjectIgnoredElement(): void
);
}

public function testDeserializeValueObjectIgnoredNamespace(): void
{
$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(): void
{
$input = <<<XML
Expand Down

0 comments on commit 8700fd8

Please sign in to comment.