diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-06-27 12:28:50 +0300 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-06-27 12:28:50 +0300 |
commit | 8a1cfa4229d0d77fa863dca64d4a434c7c03f806 (patch) | |
tree | d3fcf650e9540d76cd1e75c0d9b5dbb49e52bea8 | |
parent | 747cc45e9c45adc93ccabb0315b016ed32dccd83 (diff) | |
parent | eb76504df6a78111ccedeb2ef0a4deec1b640cca (diff) |
Merge pull request #17171 from owncloud/view-null-root-stable8
[stable8] dont allow using null as view root
-rw-r--r-- | lib/private/files/view.php | 12 | ||||
-rw-r--r-- | tests/lib/files/view.php | 17 |
2 files changed, 28 insertions, 1 deletions
diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 6f456d8b759..b07225cca56 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -35,13 +35,23 @@ class View { * @var \OC\Files\Cache\Updater */ protected $updater; - + public function __construct($root = '') { + if (is_null($root)) { + throw new \InvalidArgumentException('Root can\'t be null'); + } + if(!Filesystem::isValidPath($root)) { + throw new \Exception(); + } + $this->fakeRoot = $root; $this->updater = new Updater($this); } public function getAbsolutePath($path = '/') { + if ($path === null) { + return null; + } $this->assertPathLength($path); if ($path === '') { $path = '/'; diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index c8629abc409..f064eaaa7fd 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -1033,4 +1033,21 @@ class View extends \Test\TestCase { $view = new \OC\Files\View(''); $this->assertTrue($view->rename('/test/foo.txt', '/test/foo/bar.txt')); } + + public function testGetAbsolutePathOnNull() { + $view = new \OC\Files\View(); + $this->assertNull($view->getAbsolutePath(null)); + } + + public function testGetRelativePathOnNull() { + $view = new \OC\Files\View(); + $this->assertNull($view->getRelativePath(null)); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testNullAsRoot() { + new \OC\Files\View(null); + } } |