Merge pull request #15809 from owncloud/view-null-root
dont allow using null as view root
This commit is contained in:
commit
903d52d45f
|
@ -76,6 +76,9 @@ class View {
|
||||||
* @throws \Exception If $root contains an invalid path
|
* @throws \Exception If $root contains an invalid path
|
||||||
*/
|
*/
|
||||||
public function __construct($root = '') {
|
public function __construct($root = '') {
|
||||||
|
if (is_null($root)) {
|
||||||
|
throw new \InvalidArgumentException('Root can\'t be null');
|
||||||
|
}
|
||||||
if(!Filesystem::isValidPath($root)) {
|
if(!Filesystem::isValidPath($root)) {
|
||||||
throw new \Exception();
|
throw new \Exception();
|
||||||
}
|
}
|
||||||
|
@ -85,6 +88,9 @@ class View {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAbsolutePath($path = '/') {
|
public function getAbsolutePath($path = '/') {
|
||||||
|
if ($path === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
$this->assertPathLength($path);
|
$this->assertPathLength($path);
|
||||||
if ($path === '') {
|
if ($path === '') {
|
||||||
$path = '/';
|
$path = '/';
|
||||||
|
|
|
@ -30,7 +30,7 @@ class TemporaryNoCross extends \OC\Files\Storage\Temporary {
|
||||||
|
|
||||||
class TemporaryNoLocal extends \OC\Files\Storage\Temporary {
|
class TemporaryNoLocal extends \OC\Files\Storage\Temporary {
|
||||||
public function instanceOfStorage($className) {
|
public function instanceOfStorage($className) {
|
||||||
if($className === '\OC\Files\Storage\Local') {
|
if ($className === '\OC\Files\Storage\Local') {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return parent::instanceOfStorage($className);
|
return parent::instanceOfStorage($className);
|
||||||
|
@ -952,7 +952,7 @@ class View extends \Test\TestCase {
|
||||||
|
|
||||||
$storage2->expects($this->any())
|
$storage2->expects($this->any())
|
||||||
->method('fopen')
|
->method('fopen')
|
||||||
->will($this->returnCallback(function($path, $mode) use($storage2) {
|
->will($this->returnCallback(function ($path, $mode) use ($storage2) {
|
||||||
$source = fopen($storage2->getSourcePath($path), $mode);
|
$source = fopen($storage2->getSourcePath($path), $mode);
|
||||||
return \OC\Files\Stream\Quota::wrap($source, 9);
|
return \OC\Files\Stream\Quota::wrap($source, 9);
|
||||||
}));
|
}));
|
||||||
|
@ -1063,4 +1063,21 @@ class View extends \Test\TestCase {
|
||||||
$watcher = $storage->getWatcher();
|
$watcher = $storage->getWatcher();
|
||||||
$this->assertEquals(Watcher::CHECK_NEVER, $watcher->getPolicy());
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue