mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #28175 from nextcloud/jail-search-root
This commit is contained in:
commit
db7ffb0bf9
2 changed files with 33 additions and 11 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue