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 authored and phil-davis committed Nov 3, 2021
1 parent 38f1394 commit 43ea1d2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/DAV/Xml/Element/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,21 @@ public static function xmlDeserialize(Reader $reader)

return [];
}

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

return [];
}

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

return [];
}

$values = [];
$reader->read();

do {
if (Reader::ELEMENT === $reader->nodeType) {
$clark = $reader->getClark();
Expand All @@ -199,9 +212,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 43ea1d2

Please sign in to comment.