From fc57d4b96c11fe82a860a894b8b2e4e5a93918fb Mon Sep 17 00:00:00 2001 From: kdslkdsaldsal Date: Wed, 15 Feb 2017 09:50:36 +0100 Subject: [PATCH 1/2] Fix malformed logging in exception Signed-off-by: Morris Jobke --- lib/private/Files/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 6ffb5edff3..67356fa63c 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -2068,7 +2068,7 @@ class View { $parts = explode('/', trim($path, '/'), 3); // "$user", "files", "path/to/dir" if (!isset($parts[1]) || $parts[1] !== 'files') { - throw new \InvalidArgumentException('$absolutePath must be relative to "files"'); + throw new \InvalidArgumentException('"' . $absolutePath . '" must be relative to "files"'); } if (isset($parts[2])) { return $parts[2]; From ab9e3525cc4623ac0de24d61723dd87dce7cd605 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 20 Mar 2017 11:06:08 +0100 Subject: [PATCH 2/2] Move error message to log entry Signed-off-by: Lukas Reschke --- lib/private/Files/View.php | 13 ++++++++++++- tests/lib/Files/ViewTest.php | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 67356fa63c..506128d7fc 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -96,8 +96,12 @@ class View { private $updaterEnabled = true; + /** @var \OC\User\Manager */ private $userManager; + /** @var \OCP\ILogger */ + private $logger; + /** * @param string $root * @throws \Exception If $root contains an invalid path @@ -114,6 +118,7 @@ class View { $this->lockingProvider = \OC::$server->getLockingProvider(); $this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider); $this->userManager = \OC::$server->getUserManager(); + $this->logger = \OC::$server->getLogger(); } public function getAbsolutePath($path = '/') { @@ -2068,7 +2073,13 @@ class View { $parts = explode('/', trim($path, '/'), 3); // "$user", "files", "path/to/dir" if (!isset($parts[1]) || $parts[1] !== 'files') { - throw new \InvalidArgumentException('"' . $absolutePath . '" must be relative to "files"'); + $this->logger->error( + '$absolutePath must be relative to "files", value is "%s"', + [ + $absolutePath + ] + ); + throw new \InvalidArgumentException('$absolutePath must be relative to "files"'); } if (isset($parts[2])) { return $parts[2]; diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index 0aaeb094cd..3635323e16 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -1488,6 +1488,8 @@ class ViewTest extends \Test\TestCase { /** * @dataProvider pathRelativeToFilesProviderExceptionCases * @expectedException \InvalidArgumentException + * @expectedExceptionMessage $absolutePath must be relative to "files" + * @param string $path */ public function testGetPathRelativeToFilesWithInvalidArgument($path) { $view = new View();