Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure that files that are siblings of directories, are reported as files #982

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]);

}

}