Skip to content

Commit

Permalink
Make sure that files that are siblings of directories, are reported a…
Browse files Browse the repository at this point in the history
…s files

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jul 13, 2017
1 parent 6584481 commit 4d1dc8e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/DAV/Server.php
Expand Up @@ -894,15 +894,16 @@ private function generatePathNodes(PropFind $propFind, array $yieldFirst = null)
$newDepth--;
}

$propertyNames = $propFind->getRequestedProperties();
$propFindType = !empty($propertyNames) ? PropFind::NORMAL : PropFind::ALLPROPS;

foreach ($this->tree->getChildren($path) as $childNode) {
$subPropFind = clone $propFind;
$subPropFind->setDepth($newDepth);
if ($path !== '') {
$subPath = $path . '/' . $childNode->getName();
} else {
$subPath = $childNode->getName();
}
$subPropFind->setPath($subPath);
$subPropFind = new PropFind($subPath, $propertyNames, $newDepth, $propFindType);

yield [
$subPropFind,
Expand Down
54 changes: 54 additions & 0 deletions tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php
Expand Up @@ -160,4 +160,58 @@ function testUnknownProperty() {

}

function testFilesThatAreSiblingsOfDirectoriesShouldBeReportedAsFiles() {

$xml = '<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:">
<d:prop>
<d:resourcetype />
</d:prop>
</d:propfind>';

$this->sendRequest($xml);
$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
$xml = simplexml_load_string($body);
$xml->registerXPathNamespace('d', 'urn:DAV');
$pathTests = [
'/d:multistatus',
'/d:multistatus/d:response',
'/d:multistatus/d:response/d:href',
'/d:multistatus/d:response/d:propstat',
'/d:multistatus/d:response/d:propstat/d:status',
'/d:multistatus/d:response/d:propstat/d:prop',
'/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype',
];

$hrefPaths = [];

foreach ($pathTests as $test) {
$this->assertTrue(count($xml->xpath($test)) == true, 'We expected the ' . $test . ' element to appear in the response, we got: ' . $body);

if ($test === '/d:multistatus/d:response/d:href') {
foreach ($xml->xpath($test) as $thing) {
/** @var \SimpleXMLElement $thing */
$hrefPaths[] = strip_tags($thing->asXML());
}
} else if ($test === '/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype') {
$count = 0;
foreach ($xml->xpath($test) as $thing) {
/** @var \SimpleXMLElement $thing */
if (substr($hrefPaths[$count], -4) !== '.txt') {
$this->assertEquals('<d:resourcetype><d:collection/></d:resourcetype>', $thing->asXML(), 'Path ' . $hrefPaths[$count] . ' is not reported as a directory');
} else {
$this->assertEquals('<d:resourcetype/>', $thing->asXML(), 'Path ' . $hrefPaths[$count] . ' is not reported as a file');
}

$count++;
}
}
}

$val = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
$this->assertEquals(8, count($val), $body);
$this->assertEquals('HTTP/1.1 200 OK', (string)$val[0]);

}

}

0 comments on commit 4d1dc8e

Please sign in to comment.