Skip to content
Snippets Groups Projects
Commit aa821ecc authored by Vincent Petry's avatar Vincent Petry
Browse files

Trim leading or trailing slashes in file cache paths

parent 10505bdb
No related branches found
No related tags found
No related merge requests found
...@@ -699,6 +699,6 @@ class Cache { ...@@ -699,6 +699,6 @@ class Cache {
*/ */
public function normalize($path) { public function normalize($path) {
return \OC_Util::normalizeUnicode($path); return trim(\OC_Util::normalizeUnicode($path), '/');
} }
} }
...@@ -517,6 +517,42 @@ class Cache extends \Test\TestCase { ...@@ -517,6 +517,42 @@ class Cache extends \Test\TestCase {
$this->assertEquals(1, count($this->cache->getFolderContents('folder'))); $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() { protected function tearDown() {
if ($this->cache) { if ($this->cache) {
$this->cache->clear(); $this->cache->clear();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment