detect root of mountpoint also if the trailing slash is missed

This commit is contained in:
Bjoern Schiessle 2015-02-04 12:07:16 +01:00
parent 9e222ec841
commit 21c45925fe
2 changed files with 27 additions and 0 deletions

View File

@ -87,6 +87,11 @@ class View {
if ($this->fakeRoot == '') {
return $path;
}
if (rtrim($path,'/') === rtrim($this->fakeRoot, '/')) {
return '/';
}
if (strpos($path, $this->fakeRoot) !== 0) {
return null;
} else {

View File

@ -729,6 +729,28 @@ class View extends \Test\TestCase {
);
}
/**
* @dataProvider relativePathProvider
*/
function testGetRelativePath($absolutePath, $expectedPath) {
$view = new \OC\Files\View('/files');
// simulate a external storage mount point which has a trailing slash
$view->chroot('/files/');
$this->assertEquals($expectedPath, $view->getRelativePath($absolutePath));
}
function relativePathProvider() {
return array(
array('/files/', '/'),
array('/files', '/'),
array('/files/0', '0'),
array('/files/false', 'false'),
array('/files/true', 'true'),
array('/files/test', 'test'),
array('/files/test/foo', 'test/foo'),
);
}
public function testFileView() {
$storage = new Temporary(array());
$scanner = $storage->getScanner();