Skip to content

Commit 489c8d6

Browse files
authored
Merge pull request #275 from phil-davis/f/skipping_node_for_foreign_namespace-v3
Fixed handling of elements from foreign namespaces in values object (v3)
2 parents 9228777 + a9ed48d commit 489c8d6

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/Deserializer/functions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ function valueObject(Reader $reader, string $className, string $namespace): obje
223223
// Ignore property
224224
$reader->next();
225225
}
226+
} elseif (Reader::ELEMENT === $reader->nodeType) {
227+
// Skipping element from different namespace
228+
$reader->next();
226229
} else {
227230
if (Reader::END_ELEMENT !== $reader->nodeType && !$reader->read()) {
228231
break;

tests/Sabre/Xml/Deserializer/ValueObjectTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,43 @@ public function testDeserializeValueObjectIgnoredElement(): void
8282
);
8383
}
8484

85+
public function testDeserializeValueObjectIgnoredNamespace(): void
86+
{
87+
$input = <<<XML
88+
<?xml version="1.0"?>
89+
<foo xmlns="urn:foo" xmlns:alien="urn:example.com">
90+
<firstName>Harry</firstName>
91+
<alien:email>harry@example.org</alien:email>
92+
<lastName>Turtle</lastName>
93+
</foo>
94+
XML;
95+
96+
$reader = new Reader();
97+
$reader->xml($input);
98+
$reader->elementMap = [
99+
'{urn:foo}foo' => function (Reader $reader) {
100+
return valueObject($reader, 'Sabre\\Xml\\Deserializer\\TestVo', 'urn:foo');
101+
},
102+
];
103+
104+
$output = $reader->parse();
105+
106+
$vo = new TestVo();
107+
$vo->firstName = 'Harry';
108+
$vo->lastName = 'Turtle';
109+
110+
$expected = [
111+
'name' => '{urn:foo}foo',
112+
'value' => $vo,
113+
'attributes' => [],
114+
];
115+
116+
$this->assertEquals(
117+
$expected,
118+
$output
119+
);
120+
}
121+
85122
public function testDeserializeValueObjectAutoArray(): void
86123
{
87124
$input = <<<XML

0 commit comments

Comments
 (0)