]> source.dussan.org Git - nextcloud-server.git/commitdiff
Trim leading or trailing slashes in file cache paths
authorVincent Petry <pvince81@owncloud.com>
Thu, 8 Jan 2015 18:43:02 +0000 (19:43 +0100)
committerVincent Petry <pvince81@owncloud.com>
Thu, 8 Jan 2015 18:43:02 +0000 (19:43 +0100)
lib/private/files/cache/cache.php
tests/lib/files/cache/cache.php

index 9df64db7f07ae8c64e347599426fae7729138974..bf44cf48aa76ec719023a5f16afe8c8b35f45910 100644 (file)
@@ -699,6 +699,6 @@ class Cache {
         */
        public function normalize($path) {
 
-               return \OC_Util::normalizeUnicode($path);
+               return trim(\OC_Util::normalizeUnicode($path), '/');
        }
 }
index 81d7f3ce0bc58e093bc286eedf841c90782ea5b0..6df98ee531d8cb8b93169adbba7fd1653772cf53 100644 (file)
@@ -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();