Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix folder path containing leading slash when getting mount root by id
This fixes collabora on public link shared groupfolders

Fixes nextcloud/groupfolders#225

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 authored and Backportbot committed Nov 28, 2018
commit 7ee97810879a62d67d8865533f3a0304573a878d
2 changes: 1 addition & 1 deletion lib/private/Files/Node/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function getById($id) {
$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))
Expand Down
48 changes: 48 additions & 0 deletions tests/lib/Files/Node/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,54 @@ public function testGetById() {
$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);
/**
Expand Down