diff options
author | Julius Härtl <jus@bitgrid.net> | 2021-07-29 09:27:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-29 09:27:53 +0200 |
commit | db7ffb0bf906479c740d73fee0d469712d4a236b (patch) | |
tree | 8fcfe987ae58c4703ae96b4337aef6db8f763645 | |
parent | 9a9df238a6f60fb43cd89e1a604091edb3077686 (diff) | |
parent | 4d5e8bcb99721930ef8c4386e186b8341e598926 (diff) | |
download | nextcloud-server-db7ffb0bf906479c740d73fee0d469712d4a236b.tar.gz nextcloud-server-db7ffb0bf906479c740d73fee0d469712d4a236b.zip |
Merge pull request #28175 from nextcloud/jail-search-root
-rw-r--r-- | lib/private/Files/Cache/Wrapper/CacheJail.php | 26 | ||||
-rw-r--r-- | tests/lib/Files/Cache/Wrapper/CacheJailTest.php | 18 |
2 files changed, 33 insertions, 11 deletions
diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php index 38f47668d5d..2dff76333ad 100644 --- a/lib/private/Files/Cache/Wrapper/CacheJail.php +++ b/lib/private/Files/Cache/Wrapper/CacheJail.php @@ -306,17 +306,21 @@ class CacheJail extends CacheWrapper { } public function getQueryFilterForStorage(): ISearchOperator { - return new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, - [ - $this->getCache()->getQueryFilterForStorage(), - new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, - [ - new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', $this->getGetUnjailedRoot()), - new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $this->getGetUnjailedRoot() . '/%'), - ], - ) - ] - ); + if ($this->root !== '' && $this->root !== '/') { + return new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, + [ + $this->getCache()->getQueryFilterForStorage(), + new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, + [ + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', $this->getGetUnjailedRoot()), + new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $this->getGetUnjailedRoot() . '/%'), + ], + ) + ] + ); + } else { + return $this->getCache()->getQueryFilterForStorage(); + } } public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry { diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php index d9f7af1f034..4c3dce74087 100644 --- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php +++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php @@ -200,4 +200,22 @@ class CacheJailTest extends CacheTest { $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']); + } } |