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 Oct 10, 2017
1 parent e987775 commit 0cef604
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,12 @@
ChangeLog
=========

3.2.3 (????-??-??)
------------------

* #982: Make sure that files that are siblings of directories, are reported
as files (@nickvergessen)

3.2.2 (2017-02-14)
------------------

Expand Down
7 changes: 4 additions & 3 deletions lib/DAV/Server.php
Expand Up @@ -893,15 +893,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());
}
} elseif ($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 0cef604

Please sign in to comment.