Skip to content

Commit

Permalink
Make sure a {DAV:}prop is not empty
Browse files Browse the repository at this point in the history
Port sabre-io/xml#158 to the prop parser to sabre/dav

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
  • Loading branch information
kesselb committed Nov 2, 2021
1 parent 01ba0df commit 159cfc7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
31 changes: 24 additions & 7 deletions lib/DAV/Xml/Element/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,27 @@ public static function xmlDeserialize(Reader $reader)
// child-elements implies 'no value' in {DAV:}prop, so we want to skip
// deserializers and just set null for those.
$reader->elementMap['{DAV:}prop'] = function (Reader $reader) {
if ($reader->isEmptyElement) {
$reader->next();
// If there's no children, we don't do anything.
if ($reader->isEmptyElement) {
$reader->next();

return [];
}

if (!$reader->read()) {
$reader->next();

return [];
}

if (Reader::END_ELEMENT === $reader->nodeType) {
$reader->next();

return [];
}

$values = [];

return [];
}
$values = [];
$reader->read();
do {
if (Reader::ELEMENT === $reader->nodeType) {
$clark = $reader->getClark();
Expand All @@ -199,9 +213,12 @@ public static function xmlDeserialize(Reader $reader)
$values[$clark] = $reader->parseCurrentElement()['value'];
}
} else {
$reader->read();
if (!$reader->read()) {
break;
}
}
} while (Reader::END_ELEMENT !== $reader->nodeType);

$reader->read();

return $values;
Expand Down
31 changes: 31 additions & 0 deletions tests/Sabre/DAV/Xml/Element/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,35 @@ public function testDeserializeComplexPropertyEmpty()
$result['value']
);
}

public function testDeserializeNoProperties()
{
$xml = '<?xml version="1.0"?>
<d:response xmlns:d="DAV:">
<d:href>/uri</d:href>
<d:propstat>
<d:prop></d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
<d:propstat>
<d:prop>
<d:foo />
</d:prop>
<d:status>HTTP/1.1 404 OK</d:status>
</d:propstat>
</d:response>
';

$result = $this->parse($xml, [
'{DAV:}response' => Response::class,
]);
$this->assertEquals(
new Response('/uri', [
'404' => [
'{DAV:}foo' => null,
],
]),
$result['value']
);
}
}

0 comments on commit 159cfc7

Please sign in to comment.