diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-11-28 23:05:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-28 23:05:42 +0100 |
commit | 2b011b3626f740f04b5fbf9ff323b47d3bf73ae6 (patch) | |
tree | 8cd3006d34816653629ff24264a5d418f0a195f5 | |
parent | e1739e3da93c3260691aac8ced3867a12da25f71 (diff) | |
parent | 7ee97810879a62d67d8865533f3a0304573a878d (diff) | |
download | nextcloud-server-2b011b3626f740f04b5fbf9ff323b47d3bf73ae6.tar.gz nextcloud-server-2b011b3626f740f04b5fbf9ff323b47d3bf73ae6.zip |
Merge pull request #12715 from nextcloud/backport/12708/stable14
[stable14] Fix folder path containing leading slash when getting mount root by id
-rw-r--r-- | lib/private/Files/Node/Folder.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/Node/FolderTest.php | 48 |
2 files changed, 49 insertions, 1 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index 0eb119eb0de..e35ca85a779 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -313,7 +313,7 @@ class Folder extends Node implements \OCP\Files\Folder { $internalPath = ltrim($cachedMountInfo->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); - $absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount; + $absolutePath = rtrim($cachedMountInfo->getMountPoint() . $pathRelativeToMount, '/'); return $this->root->createNode($absolutePath, new \OC\Files\FileInfo( $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount, \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount)) diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index c924c090232..2c87b645dd9 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -613,6 +613,54 @@ class FolderTest extends NodeTest { $this->assertEquals('/bar/foo/qwerty', $result[0]->getPath()); } + public function testGetByIdMountRoot() { + $manager = $this->createMock(Manager::class); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->createMock(View::class); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); + $storage = $this->createMock(\OC\Files\Storage\Storage::class); + $mount = new MountPoint($storage, '/bar'); + $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock(); + + $fileInfo = new CacheEntry(['path' => '', 'mimetype' => 'text/plain'], null); + + $storage->expects($this->once()) + ->method('getCache') + ->will($this->returnValue($cache)); + + $this->userMountCache->expects($this->any()) + ->method('getMountsForFileId') + ->with(1) + ->will($this->returnValue([new CachedMountInfo( + $this->user, + 1, + 0, + '/bar/', + 1, + '' + )])); + + $cache->expects($this->once()) + ->method('get') + ->with(1) + ->will($this->returnValue($fileInfo)); + + $root->expects($this->once()) + ->method('getMount') + ->with('/bar') + ->will($this->returnValue($mount)); + + $node = new \OC\Files\Node\Folder($root, $view, '/bar'); + $result = $node->getById(1); + $this->assertEquals(1, count($result)); + $this->assertEquals('/bar', $result[0]->getPath()); + } + public function testGetByIdOutsideFolder() { $manager = $this->createMock(Manager::class); /** |