Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-07-08 11:36:20 +0300
committerMorris Jobke <hey@morrisjobke.de>2015-07-08 11:36:20 +0300
commitf97b21da11e59c00af395f6e2d5011f1f2e8963a (patch)
tree641bb149d448920b800b4fcd59f3c9247a71dd29
parent8b0b6924f59334f3ca6a1e979e3cc4a577a114cf (diff)
parenta9a5ac2fd17a72ea87ed00d15131048ec1ebf607 (diff)
Merge pull request #17172 from owncloud/view-emit-path-stable8
[stable8] emit hooks from a view as long as the path is inside the default root
-rw-r--r--lib/private/files/view.php6
-rw-r--r--tests/lib/files/view.php29
2 files changed, 33 insertions, 2 deletions
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index b07225cca56..1ad59fd9123 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -898,7 +898,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 . '/');
}
/**
@@ -908,10 +909,11 @@ class View {
* @return bool
*/
private function runHooks($hooks, $path, $post = false) {
+ $relativePath = $path;
$path = $this->getHookPath($path);
$prefix = ($post) ? 'post_' : '';
$run = true;
- if ($this->shouldEmitHooks($path)) {
+ if ($this->shouldEmitHooks($relativePath)) {
foreach ($hooks as $hook) {
if ($hook != 'read') {
\OC_Hook::emit(
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index f064eaaa7fd..c595afb5022 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -1050,4 +1050,33 @@ class View extends \Test\TestCase {
public function testNullAsRoot() {
new \OC\Files\View(null);
}
+
+ 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);
+ }
}