emit hooks from a view as long as the path is inside the default root

This commit is contained in:
Robin Appelman 2015-06-01 14:08:14 +02:00
parent 3ebc8f0564
commit 4b48dd424f
2 changed files with 31 additions and 1 deletions

View File

@ -1063,7 +1063,8 @@ class View {
if ($this->fakeRoot === $defaultRoot) {
return true;
}
return (strlen($this->fakeRoot) > strlen($defaultRoot)) && (substr($this->fakeRoot, 0, strlen($defaultRoot) + 1) === $defaultRoot . '/');
$fullPath = $this->getAbsolutePath($path);
return (strlen($fullPath) > strlen($defaultRoot)) && (substr($fullPath, 0, strlen($defaultRoot) + 1) === $defaultRoot . '/');
}
/**

View File

@ -1107,4 +1107,33 @@ class View extends \Test\TestCase {
$view->lockFile('/foo/bar', ILockingProvider::LOCK_SHARED);
$view->lockFile('/foo/bar', ILockingProvider::LOCK_EXCLUSIVE);
}
public function hookPathProvider() {
return [
['/foo/files', '/foo', true],
['/foo/files/bar', '/foo', true],
['/foo', '/foo', false],
['/foo', '/files/foo', true],
['/foo', 'filesfoo', false]
];
}
/**
* @dataProvider hookPathProvider
* @param $root
* @param $path
* @param $shouldEmit
*/
public function testHookPaths($root, $path, $shouldEmit) {
$filesystemReflection = new \ReflectionClass('\OC\Files\Filesystem');
$defaultRootValue = $filesystemReflection->getProperty('defaultInstance');
$defaultRootValue->setAccessible(true);
$oldRoot = $defaultRootValue->getValue();
$defaultView = new \OC\Files\View('/foo/files');
$defaultRootValue->setValue($defaultView);
$view = new \OC\Files\View($root);
$result = \Test_Helper::invokePrivate($view, 'shouldEmitHooks', [$path]);
$defaultRootValue->setValue($oldRoot);
$this->assertEquals($shouldEmit, $result);
}
}