diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php index 586c843e08e83..b456bfccd1916 100644 --- a/lib/private/Files/Cache/Wrapper/CacheJail.php +++ b/lib/private/Files/Cache/Wrapper/CacheJail.php @@ -244,6 +244,10 @@ private function formatSearchResults($results) { * @return array an array of file data */ public function search($pattern) { + if ($this->getGetUnjailedRoot() === '' || $this->getGetUnjailedRoot() === '/') { + return parent::search($pattern); + } + // normalize pattern $pattern = $this->normalize($pattern); @@ -277,6 +281,10 @@ public function search($pattern) { * @return array */ public function searchByMime($mimetype) { + if ($this->getGetUnjailedRoot() === '' || $this->getGetUnjailedRoot() === '/') { + return parent::searchByMime($mimetype); + } + $mimeId = $this->mimetypeLoader->getId($mimetype); $query = $this->getQueryBuilder(); @@ -304,6 +312,10 @@ public function searchByMime($mimetype) { } public function searchQuery(ISearchQuery $query) { + if ($this->getGetUnjailedRoot() === '' || $this->getGetUnjailedRoot() === '/') { + return parent::searchQuery($query); + } + $prefixFilter = new SearchComparison( ISearchComparison::COMPARE_LIKE, 'path', diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php index d9f7af1f03435..4c3dce740878b 100644 --- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php +++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php @@ -200,4 +200,22 @@ public function testSearchNested() { $this->assertCount(1, $result); $this->assertEquals('asd', $result[0]['path']); } + + public function testRootJail() { + $this->storage->getScanner()->scan(''); + $file1 = 'foo'; + $file2 = 'foo/bar'; + $file3 = 'foo/bar/asd'; + $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder']; + + $this->sourceCache->put($file1, $data1); + $this->sourceCache->put($file2, $data1); + $this->sourceCache->put($file3, $data1); + + $nested = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, ''); + + $result = $nested->search('%asd%'); + $this->assertCount(1, $result); + $this->assertEquals('foo/bar/asd', $result[0]['path']); + } }