Skip to content

Commit 9353802

Browse files
authored
Merge pull request #28235 from nextcloud/jail-search-root-21
[21] dont apply jail search filter is on the root
2 parents 486f716 + a9fbd0b commit 9353802

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

lib/private/Files/Cache/Wrapper/CacheJail.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ private function formatSearchResults($results) {
244244
* @return array an array of file data
245245
*/
246246
public function search($pattern) {
247+
if ($this->getGetUnjailedRoot() === '' || $this->getGetUnjailedRoot() === '/') {
248+
return parent::search($pattern);
249+
}
250+
247251
// normalize pattern
248252
$pattern = $this->normalize($pattern);
249253

@@ -277,6 +281,10 @@ public function search($pattern) {
277281
* @return array
278282
*/
279283
public function searchByMime($mimetype) {
284+
if ($this->getGetUnjailedRoot() === '' || $this->getGetUnjailedRoot() === '/') {
285+
return parent::searchByMime($mimetype);
286+
}
287+
280288
$mimeId = $this->mimetypeLoader->getId($mimetype);
281289

282290
$query = $this->getQueryBuilder();
@@ -304,6 +312,10 @@ public function searchByMime($mimetype) {
304312
}
305313

306314
public function searchQuery(ISearchQuery $query) {
315+
if ($this->getGetUnjailedRoot() === '' || $this->getGetUnjailedRoot() === '/') {
316+
return parent::searchQuery($query);
317+
}
318+
307319
$prefixFilter = new SearchComparison(
308320
ISearchComparison::COMPARE_LIKE,
309321
'path',

tests/lib/Files/Cache/Wrapper/CacheJailTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,22 @@ public function testSearchNested() {
200200
$this->assertCount(1, $result);
201201
$this->assertEquals('asd', $result[0]['path']);
202202
}
203+
204+
public function testRootJail() {
205+
$this->storage->getScanner()->scan('');
206+
$file1 = 'foo';
207+
$file2 = 'foo/bar';
208+
$file3 = 'foo/bar/asd';
209+
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
210+
211+
$this->sourceCache->put($file1, $data1);
212+
$this->sourceCache->put($file2, $data1);
213+
$this->sourceCache->put($file3, $data1);
214+
215+
$nested = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, '');
216+
217+
$result = $nested->search('%asd%');
218+
$this->assertCount(1, $result);
219+
$this->assertEquals('foo/bar/asd', $result[0]['path']);
220+
}
203221
}

0 commit comments

Comments
 (0)