Skip to content

Commit

Permalink
Make sure a {DAV:}prop is not empty
Browse files Browse the repository at this point in the history
<d:prop/> => isEmptyElement = true, readInnerXml = ''
<d:prop></d:prop> => isEmptyElement = false, readInnerXml = ''

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
  • Loading branch information
kesselb committed Oct 9, 2021
1 parent c1afdc7 commit ee03532
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/DAV/Xml/Element/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ 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) {
if ($reader->isEmptyElement || '' === $reader->readInnerXml()) {
$reader->next();

return [];
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 ee03532

Please sign in to comment.