]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix folder path containing leading slash when getting mount root by id 12715/head
authorRobin Appelman <robin@icewind.nl>
Wed, 28 Nov 2018 14:18:29 +0000 (15:18 +0100)
committerBackportbot <backportbot-noreply@rullzer.com>
Wed, 28 Nov 2018 19:07:51 +0000 (19:07 +0000)
This fixes collabora on public link shared groupfolders

Fixes https://github.com/nextcloud/groupfolders/issues/225

Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/Node/Folder.php
tests/lib/Files/Node/FolderTest.php

index 0eb119eb0de3e0a387461f392d5fd218adc15eaa..e35ca85a779ab7647f89415fd53ceafaf8122ca8 100644 (file)
@@ -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))
index c924c090232b584b90c71fa6056fc0d00951d375..2c87b645dd9befc279b1076baa146b57f819a98d 100644 (file)
@@ -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);
                /**