summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-04-22 18:10:26 +0200
committerVincent Petry <pvince81@owncloud.com>2015-04-22 18:10:26 +0200
commit903d52d45f1b0de3a3346fa837238f2d9cdff57b (patch)
tree25e1e367853b0b8e48bca385fc8ac0600f16f1c5
parent750f0bc4896dcc35695e535ae826da353d265daf (diff)
parentbd57902d1d1d368bcf8a1fc5d3aa8d966d81eddf (diff)
downloadnextcloud-server-903d52d45f1b0de3a3346fa837238f2d9cdff57b.tar.gz
nextcloud-server-903d52d45f1b0de3a3346fa837238f2d9cdff57b.zip
Merge pull request #15809 from owncloud/view-null-root
dont allow using null as view root
-rw-r--r--lib/private/files/view.php6
-rw-r--r--tests/lib/files/view.php21
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 3300998da35..162bf568de7 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -76,6 +76,9 @@ class View {
* @throws \Exception If $root contains an invalid path
*/
public function __construct($root = '') {
+ if (is_null($root)) {
+ throw new \InvalidArgumentException('Root can\'t be null');
+ }
if(!Filesystem::isValidPath($root)) {
throw new \Exception();
}
@@ -85,6 +88,9 @@ class View {
}
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 269b8b23e7d..6bc63557138 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -30,7 +30,7 @@ class TemporaryNoCross extends \OC\Files\Storage\Temporary {
class TemporaryNoLocal extends \OC\Files\Storage\Temporary {
public function instanceOfStorage($className) {
- if($className === '\OC\Files\Storage\Local') {
+ if ($className === '\OC\Files\Storage\Local') {
return false;
} else {
return parent::instanceOfStorage($className);
@@ -952,7 +952,7 @@ class View extends \Test\TestCase {
$storage2->expects($this->any())
->method('fopen')
- ->will($this->returnCallback(function($path, $mode) use($storage2) {
+ ->will($this->returnCallback(function ($path, $mode) use ($storage2) {
$source = fopen($storage2->getSourcePath($path), $mode);
return \OC\Files\Stream\Quota::wrap($source, 9);
}));
@@ -1063,4 +1063,21 @@ class View extends \Test\TestCase {
$watcher = $storage->getWatcher();
$this->assertEquals(Watcher::CHECK_NEVER, $watcher->getPolicy());
}
+
+ 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);
+ }
}