files: when filtering search results, ensure results are children of the fakeroot not just path starting the same
This commit is contained in:
parent
5b95e7aa0f
commit
a1d4eb1f95
|
@ -975,7 +975,7 @@ class View {
|
||||||
/**
|
/**
|
||||||
* search for files by mimetype
|
* search for files by mimetype
|
||||||
*
|
*
|
||||||
* @param string $query
|
* @param string $mimetype
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function searchByMime($mimetype) {
|
public function searchByMime($mimetype) {
|
||||||
|
@ -998,7 +998,7 @@ class View {
|
||||||
|
|
||||||
$results = $cache->$method($query);
|
$results = $cache->$method($query);
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
if (substr($mountPoint . $result['path'], 0, $rootLength) === $this->fakeRoot) {
|
if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') {
|
||||||
$result['path'] = substr($mountPoint . $result['path'], $rootLength);
|
$result['path'] = substr($mountPoint . $result['path'], $rootLength);
|
||||||
$files[] = $result;
|
$files[] = $result;
|
||||||
}
|
}
|
||||||
|
@ -1012,6 +1012,7 @@ class View {
|
||||||
|
|
||||||
$relativeMountPoint = substr($mountPoint, $rootLength);
|
$relativeMountPoint = substr($mountPoint, $rootLength);
|
||||||
$results = $cache->$method($query);
|
$results = $cache->$method($query);
|
||||||
|
if ($results) {
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
$result['path'] = $relativeMountPoint . $result['path'];
|
$result['path'] = $relativeMountPoint . $result['path'];
|
||||||
$files[] = $result;
|
$files[] = $result;
|
||||||
|
@ -1019,6 +1020,7 @@ class View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -354,8 +354,22 @@ class View extends \PHPUnit_Framework_TestCase {
|
||||||
$this->hookPath = $params['path'];
|
$this->hookPath = $params['path'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSearchNotOutsideView() {
|
||||||
|
$storage1 = $this->getTestStorage();
|
||||||
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
||||||
|
$storage1->rename('folder', 'foo');
|
||||||
|
$scanner = $storage1->getScanner();
|
||||||
|
$scanner->scan('');
|
||||||
|
|
||||||
|
$view = new \OC\Files\View('/foo');
|
||||||
|
|
||||||
|
$result = $view->search('.txt');
|
||||||
|
$this->assertCount(1, $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $scan
|
* @param bool $scan
|
||||||
|
* @param string $class
|
||||||
* @return \OC\Files\Storage\Storage
|
* @return \OC\Files\Storage\Storage
|
||||||
*/
|
*/
|
||||||
private function getTestStorage($scan = true, $class = '\OC\Files\Storage\Temporary') {
|
private function getTestStorage($scan = true, $class = '\OC\Files\Storage\Temporary') {
|
||||||
|
|
Loading…
Reference in New Issue