From f1e01dbbbc64d4d8b5d84d4979ef80f505376b31 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 12 Feb 2018 16:05:42 +0100 Subject: [PATCH] Fix path handling for activities Signed-off-by: Joas Schilling --- apps/files/lib/Activity/Provider.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php index eab7e4e44e..83f5dbaf78 100644 --- a/apps/files/lib/Activity/Provider.php +++ b/apps/files/lib/Activity/Provider.php @@ -29,6 +29,7 @@ use OCP\Activity\IEventMerger; use OCP\Activity\IManager; use OCP\Activity\IProvider; use OCP\Files\Folder; +use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; @@ -342,13 +343,25 @@ class Provider implements IProvider { $encryptionContainer = $this->getEndToEndEncryptionContainer($id, basename($path)); if ($encryptionContainer instanceof Folder) { $this->fileIsEncrypted = true; - return [ - 'type' => 'file', - 'id' => $encryptionContainer->getId(), - 'name' => $encryptionContainer->getName(), - 'path' => trim($encryptionContainer->getPath(), '/'), // FIXME remove /user/files/... - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $encryptionContainer->getId()]), - ]; + try { + $fullPath = rtrim($encryptionContainer->getPath(), '/'); + // Remove /user/files/... + list(,,, $path) = explode('/', $fullPath, 4); + if (!$path) { + throw new InvalidPathException('Path could not be split correctly'); + } + + return [ + 'type' => 'file', + 'id' => $encryptionContainer->getId(), + 'name' => $encryptionContainer->getName(), + 'path' => $path, + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $encryptionContainer->getId()]), + ]; + } catch (\Exception $e) { + // fall back to the normal one + $this->fileIsEncrypted = false; + } } return [