summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-01-10 17:35:40 +0100
committerMorris Jobke <hey@morrisjobke.de>2015-01-10 17:35:40 +0100
commitc91d47e5b3ad8b2b6d30f7f4fdeff1a1d7e744a5 (patch)
treeb53758a37f09c65a40f023dc4655203bf8df2d11
parentc259733b881138c273b4af18d788f3df53497871 (diff)
parent05615bfd473f1eafa4ec253779568ab044467ceb (diff)
downloadnextcloud-server-c91d47e5b3ad8b2b6d30f7f4fdeff1a1d7e744a5.tar.gz
nextcloud-server-c91d47e5b3ad8b2b6d30f7f4fdeff1a1d7e744a5.zip
Merge pull request #13224 from owncloud/simplify-is-valid-path-and-add-unit-tests
Simplify isValidPath and add unit tests
-rw-r--r--lib/private/files/filesystem.php2
-rw-r--r--tests/lib/files/filesystem.php33
2 files changed, 34 insertions, 1 deletions
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index bc43eb5d1ce..100b364ca06 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -504,7 +504,7 @@ class Filesystem {
if (!$path || $path[0] !== '/') {
$path = '/' . $path;
}
- if (strstr($path, '/../') || strrchr($path, '/') === '/..') {
+ if (strpos($path, '/../') !== FALSE || strrchr($path, '/') === '/..') {
return false;
}
return true;
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index 1b84db0fc0d..888690adb0e 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -154,6 +154,39 @@ class Filesystem extends \Test\TestCase {
$this->assertEquals($expected, \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash));
}
+ public function isValidPathData() {
+ return array(
+ array('/', true),
+ array('/path', true),
+ array('/foo/bar', true),
+ array('/foo//bar/', true),
+ array('/foo////bar', true),
+ array('/foo//\///bar', true),
+ array('/foo/bar/.', true),
+ array('/foo/bar/./', true),
+ array('/foo/bar/./.', true),
+ array('/foo/bar/././', true),
+ array('/foo/bar/././..bar', true),
+ array('/foo/bar/././..bar/a', true),
+ array('/foo/bar/././..', false),
+ array('/foo/bar/././../', false),
+ array('/foo/bar/.././', false),
+ array('/foo/bar/../../', false),
+ array('/foo/bar/../..\\', false),
+ array('..', false),
+ array('../', false),
+ array('../foo/bar', false),
+ array('..\foo/bar', false),
+ );
+ }
+
+ /**
+ * @dataProvider isValidPathData
+ */
+ public function testIsValidPath($path, $expected) {
+ $this->assertSame($expected, \OC\Files\Filesystem::isValidPath($path));
+ }
+
public function normalizePathWindowsAbsolutePathData() {
return array(
array('C:/', 'C:\\'),