Prevent wrong matches in getRelativePath
Before this fix, the root "/files" with path "/files_trashbin" would return "_trashbin" as relative path...
This commit is contained in:
parent
67231ed9a7
commit
b9cd5bc1dc
|
@ -153,7 +153,10 @@ class View {
|
|||
return '/';
|
||||
}
|
||||
|
||||
if (strpos($path, $this->fakeRoot) !== 0) {
|
||||
// missing slashes can cause wrong matches!
|
||||
$root = rtrim($this->fakeRoot, '/') . '/';
|
||||
|
||||
if (strpos($path, $root) !== 0) {
|
||||
return null;
|
||||
} else {
|
||||
$path = substr($path, strlen($this->fakeRoot));
|
||||
|
|
|
@ -853,22 +853,29 @@ class View extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider relativePathProvider
|
||||
*/
|
||||
function testGetRelativePath($absolutePath, $expectedPath) {
|
||||
function testGetRelativePath($root, $absolutePath, $expectedPath) {
|
||||
$view = new \OC\Files\View('/files');
|
||||
// simulate a external storage mount point which has a trailing slash
|
||||
$view->chroot('/files/');
|
||||
$view->chroot($root);
|
||||
$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'),
|
||||
// TODO: add many more cases with mixed slashes, which is only possible
|
||||
// once getRelativePath's behavior is made consistent
|
||||
|
||||
// with slashes
|
||||
array('/files/', '/files/', '/'),
|
||||
array('/files/', '/files', '/'),
|
||||
array('/files/', '/files/0', '0'),
|
||||
array('/files/', '/files/false', 'false'),
|
||||
array('/files/', '/files/true', 'true'),
|
||||
array('/files/', '/files/test', 'test'),
|
||||
array('/files/', '/files/test/foo', 'test/foo'),
|
||||
// mix
|
||||
array('files', 'files_trashbin/test', null),
|
||||
array('/files', '/files_trashbin/test', null),
|
||||
array('/files', 'files_trashbin/test', null),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue