summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/files/cache/cache.php2
-rw-r--r--lib/private/files/cache/wrapper/cachejail.php2
-rw-r--r--tests/lib/files/cache/cache.php36
3 files changed, 38 insertions, 2 deletions
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index 9df64db7f07..bf44cf48aa7 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -699,6 +699,6 @@ class Cache {
*/
public function normalize($path) {
- return \OC_Util::normalizeUnicode($path);
+ return trim(\OC_Util::normalizeUnicode($path), '/');
}
}
diff --git a/lib/private/files/cache/wrapper/cachejail.php b/lib/private/files/cache/wrapper/cachejail.php
index f4ffc67d76a..3f7ea66ea1b 100644
--- a/lib/private/files/cache/wrapper/cachejail.php
+++ b/lib/private/files/cache/wrapper/cachejail.php
@@ -30,7 +30,7 @@ class CacheJail extends CacheWrapper {
if ($path === '') {
return $this->root;
} else {
- return $this->root . '/' . $path;
+ return $this->root . '/' . ltrim($path, '/');
}
}
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 81d7f3ce0bc..6df98ee531d 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -517,6 +517,42 @@ class Cache extends \Test\TestCase {
$this->assertEquals(1, count($this->cache->getFolderContents('folder')));
}
+ function bogusPathNamesProvider() {
+ return array(
+ array('/bogus.txt', 'bogus.txt'),
+ array('//bogus.txt', 'bogus.txt'),
+ array('bogus/', 'bogus'),
+ array('bogus//', 'bogus'),
+ );
+ }
+
+ /**
+ * Test bogus paths with leading or doubled slashes
+ *
+ * @dataProvider bogusPathNamesProvider
+ */
+ public function testBogusPaths($bogusPath, $fixedBogusPath) {
+ $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+ // put root folder
+ $this->assertFalse($this->cache->get(''));
+ $parentId = $this->cache->put('', $data);
+ $this->assertGreaterThan(0, $parentId);
+
+ $this->assertGreaterThan(0, $this->cache->put($bogusPath, $data));
+
+ $newData = $this->cache->get($fixedBogusPath);
+ $this->assertNotFalse($newData);
+
+ $this->assertEquals($fixedBogusPath, $newData['path']);
+ // parent is the correct one, resolved properly (they used to not be)
+ $this->assertEquals($parentId, $newData['parent']);
+
+ $newDataFromBogus = $this->cache->get($bogusPath);
+ // same entry
+ $this->assertEquals($newData, $newDataFromBogus);
+ }
+
protected function tearDown() {
if ($this->cache) {
$this->cache->clear();