Merge pull request #28235 from nextcloud/jail-search-root-21

[21] dont apply jail search filter is on the root
This commit is contained in:
Vincent Petry 2021-07-29 16:37:35 +02:00 committed by GitHub
commit 9353802ba4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -244,6 +244,10 @@ class CacheJail extends CacheWrapper {
* @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 @@ class CacheJail extends CacheWrapper {
* @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 @@ class CacheJail extends CacheWrapper {
}
public function searchQuery(ISearchQuery $query) {
if ($this->getGetUnjailedRoot() === '' || $this->getGetUnjailedRoot() === '/') {
return parent::searchQuery($query);
}
$prefixFilter = new SearchComparison(
ISearchComparison::COMPARE_LIKE,
'path',

View file

@ -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']);
}
}