Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/private/Files/Cache/Wrapper/CacheJail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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',
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/Files/Cache/Wrapper/CacheJailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}