]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix searchCommon to properly match path name
authorVincent Petry <pvince81@owncloud.com>
Mon, 12 Jan 2015 18:33:00 +0000 (19:33 +0100)
committerVincent Petry <pvince81@owncloud.com>
Mon, 12 Jan 2015 18:33:00 +0000 (19:33 +0100)
The internal path was matched without the last "/" which caused
"files_trashbin" to also match when the internal path was "files".

This adds the missing slash for the comparison.

lib/private/files/node/folder.php
tests/lib/files/node/folder.php

index bdfb2346716d240c9967d5ec4febb6b7348be86e..5fd73cc5d3614a9623ddab6d522fbdd0991887b2 100644 (file)
@@ -259,6 +259,7 @@ class Folder extends Node implements \OCP\Files\Folder {
                 * @var \OC\Files\Storage\Storage $storage
                 */
                list($storage, $internalPath) = $this->view->resolvePath($this->path);
+               $internalPath = rtrim($internalPath, '/') . '/';
                $internalRootLength = strlen($internalPath);
 
                $cache = $storage->getCache('');
index bcd9cc93b5e87147fa989c40c0f367bd5136225a..54b26ebdfe181755751113f621e3670589cb4e6d 100644 (file)
@@ -405,6 +405,45 @@ class Folder extends \Test\TestCase {
                $this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
        }
 
+       public function testSearchInRoot() {
+               $manager = $this->getMock('\OC\Files\Mount\Manager');
+               /**
+                * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+                */
+               $view = $this->getMock('\OC\Files\View');
+               $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn'), array($manager, $view, $this->user));
+               $root->expects($this->any())
+                       ->method('getUser')
+                       ->will($this->returnValue($this->user));
+               $storage = $this->getMock('\OC\Files\Storage\Storage');
+               $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+
+               $storage->expects($this->once())
+                       ->method('getCache')
+                       ->will($this->returnValue($cache));
+
+               $cache->expects($this->once())
+                       ->method('search')
+                       ->with('%qw%')
+                       ->will($this->returnValue(array(
+                               array('fileid' => 3, 'path' => 'files/foo', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'),
+                               array('fileid' => 3, 'path' => 'files_trashbin/foo2.d12345', 'name' => 'foo2.d12345', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'),
+                       )));
+
+               $root->expects($this->once())
+                       ->method('getMountsIn')
+                       ->with('')
+                       ->will($this->returnValue(array()));
+
+               $view->expects($this->once())
+                       ->method('resolvePath')
+                       ->will($this->returnValue(array($storage, 'files')));
+
+               $result = $root->search('qw');
+               $this->assertEquals(1, count($result));
+               $this->assertEquals('/foo', $result[0]->getPath());
+       }
+
        public function testSearchByTag() {
                $manager = $this->getMock('\OC\Files\Mount\Manager');
                /**