diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-02-27 02:56:13 -0800 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-02-27 02:56:13 -0800 |
commit | 7fe07e93fe4706962d2957d252b009513459d15e (patch) | |
tree | 306f1219e4bccdba2e09ececfe5432a163f66eda | |
parent | 1c6857d92c835d499e37bebd24aaf325373dc7f1 (diff) | |
parent | 541c8c092db947814a25f452a78a38f2cd2ff791 (diff) | |
download | nextcloud-server-7fe07e93fe4706962d2957d252b009513459d15e.tar.gz nextcloud-server-7fe07e93fe4706962d2957d252b009513459d15e.zip |
Merge pull request #14437 from owncloud/node-check-fileinfo
Check if we have a proper fileinfo
-rw-r--r-- | lib/private/files/node/node.php | 18 | ||||
-rw-r--r-- | tests/lib/files/node/node.php | 15 |
2 files changed, 31 insertions, 2 deletions
diff --git a/lib/private/files/node/node.php b/lib/private/files/node/node.php index 536483fc89d..9446bff603e 100644 --- a/lib/private/files/node/node.php +++ b/lib/private/files/node/node.php @@ -8,6 +8,10 @@ namespace OC\Files\Node; +use OC\Files\Filesystem; +use OCP\Files\FileInfo; +use OCP\Files\InvalidPathException; +use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; class Node implements \OCP\Files\Node { @@ -45,11 +49,21 @@ class Node implements \OCP\Files\Node { /** * Returns the matching file info * - * @return \OCP\Files\FileInfo + * @return FileInfo + * @throws InvalidPathException + * @throws NotFoundException */ public function getFileInfo() { + if (!Filesystem::isValidPath($this->path)) { + throw new InvalidPathException(); + } if (!$this->fileInfo) { - $this->fileInfo = $this->view->getFileInfo($this->path); + $fileInfo = $this->view->getFileInfo($this->path); + if ($fileInfo instanceof FileInfo) { + $this->fileInfo = $fileInfo; + } else { + throw new NotFoundException(); + } } return $this->fileInfo; } diff --git a/tests/lib/files/node/node.php b/tests/lib/files/node/node.php index 49a2006c767..01ed84c4a06 100644 --- a/tests/lib/files/node/node.php +++ b/tests/lib/files/node/node.php @@ -340,4 +340,19 @@ class Node extends \Test\TestCase { $node = new \OC\Files\Node\Node($root, $view, '/bar/foo'); $node->touch(100); } + + /** + * @expectedException \OCP\Files\InvalidPathException + */ + public function testInvalidPath() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + + $node = new \OC\Files\Node\Node($root, $view, '/../foo'); + $node->getFileInfo(); + } } |