summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorin Peter <github@florin-peter.de>2013-05-23 20:29:46 +0200
committerFlorin Peter <github@florin-peter.de>2013-05-23 20:29:46 +0200
commitd4b700ef4ebfa9aba9bcadda864ed5a2a92174ed (patch)
treedd5c32ef990fdc38bc9ed3c31ffb1c74e3077507
parent85e0c78166d45b0ef9d00b1fd2164e4969ee9b83 (diff)
downloadnextcloud-server-d4b700ef4ebfa9aba9bcadda864ed5a2a92174ed.tar.gz
nextcloud-server-d4b700ef4ebfa9aba9bcadda864ed5a2a92174ed.zip
revert previous fix and added normalizer to cache class
-rw-r--r--lib/files/cache/cache.php24
-rw-r--r--lib/files/cache/scanner.php2
-rw-r--r--tests/lib/files/cache/cache.php67
3 files changed, 92 insertions, 1 deletions
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index 3341fe50525..a7e634c8e41 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -100,6 +100,9 @@ class Cache {
*/
public function get($file) {
if (is_string($file) or $file == '') {
+ // normalize file
+ $file = $this->normalize($file);
+
$where = 'WHERE `storage` = ? AND `path_hash` = ?';
$params = array($this->getNumericStorageId(), md5($file));
} else { //file id
@@ -177,6 +180,9 @@ class Cache {
$this->update($id, $data);
return $id;
} else {
+ // normalize file
+ $file = $this->normalize($file);
+
if (isset($this->partial[$file])) { //add any saved partial data
$data = array_merge($this->partial[$file], $data);
unset($this->partial[$file]);
@@ -265,6 +271,9 @@ class Cache {
* @return int
*/
public function getId($file) {
+ // normalize file
+ $file = $this->normalize($file);
+
$pathHash = md5($file);
$query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
@@ -549,4 +558,19 @@ class Cache {
return null;
}
}
+
+ /**
+ * normalize the given path
+ * @param $path
+ * @return string
+ */
+ public function normalize($path) {
+
+ //normalize unicode if possible
+ if (class_exists('Normalizer')) {
+ $path = \Normalizer::normalize($path);
+ }
+
+ return $path;
+ }
}
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index b73e2e83fcc..a98953b42aa 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -114,7 +114,7 @@ class Scanner {
$size = 0;
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
\OC_DB::beginTransaction();
- while ($file = utf8_encode(readdir($dh))) {
+ while ($file = readdir($dh)) {
$child = ($path) ? $path . '/' . $file : $file;
if (!$this->isIgnoredDir($file)) {
$data = $this->scanFile($child, $recursive === self::SCAN_SHALLOW);
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 1612a673838..2b1e5a56212 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -8,6 +8,8 @@
namespace Test\Files\Cache;
+use PHPUnit_Framework_MockObject_MockObject;
+
class LongId extends \OC\Files\Storage\Temporary {
public function getId() {
return 'long:' . str_repeat('foo', 50) . parent::getId();
@@ -237,6 +239,71 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertEquals(array(md5($storageId), 'foo'), \OC\Files\Cache\Cache::getById($id));
}
+ /**
+ * @brief this test show the bug resulting if we have no normalizer installed
+ */
+ public function testWithoutNormalizer() {
+ // create folder Schön with U+00F6
+ $folderWith00F6 = "\x53\x63\x68\xc3\xb6\x6e";
+
+ // create folder Schön with U+0308
+ $folderWith0308 = "\x53\x63\x68\x6f\xcc\x88\x6e";
+
+ /**
+ * @var \OC\Files\Cache\Cache | PHPUnit_Framework_MockObject_MockObject $cacheMock
+ */
+ $cacheMock = $this->getMock('\OC\Files\Cache\Cache', array('normalize'), array($this->storage), '', true);
+
+ $cacheMock->expects($this->any())
+ ->method('normalize')
+ ->will($this->returnArgument(0));
+
+ $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+ $this->assertFalse($cacheMock->get('folder'));
+ $this->assertGreaterThan(0, $cacheMock->put('folder', $data));
+
+ $this->assertFalse($cacheMock->get('folder/' . $folderWith00F6));
+ $this->assertGreaterThan(0, $cacheMock->put('folder/' .$folderWith00F6, $data));
+
+ $this->assertFalse($cacheMock->get('folder/' .$folderWith0308));
+ $this->assertGreaterThan(0, $cacheMock->put('folder/' .$folderWith0308, $data));
+
+ // this is our bug, we have two different hashes with the same name (Schön)
+ $this->assertEquals(2, count($cacheMock->getFolderContents('folder')));
+ }
+
+ /**
+ * @brief this test shows that there is no bug if we use the normalizer
+ */
+ public function testWithNormalizer() {
+
+ if(!class_exists('Normalizer')) {
+ $this->markTestSkipped('The Normalizer extension is not available.');
+ return;
+ }
+
+ // folder name Schön with U+00F6
+ $folderWith00F6 = "\x53\x63\x68\xc3\xb6\x6e";
+
+ // folder name Schön with U+0308
+ $folderWith0308 = "\x53\x63\x68\x6f\xcc\x88\x6e";
+
+ $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+ $this->assertFalse($this->cache->get('folder'));
+ $this->assertGreaterThan(0, $this->cache->put('folder', $data));
+
+ $this->assertFalse($this->cache->get('folder/' . $folderWith00F6));
+ $this->assertGreaterThan(0, $this->cache->put('folder/' .$folderWith00F6, $data));
+
+ $this->assertTrue(is_array($this->cache->get('folder/' .$folderWith0308)));
+ $this->assertGreaterThan(0, $this->cache->put('folder/' .$folderWith0308, $data));
+
+ // at this point we should have only one folder named "Schön"
+ $this->assertEquals(1, count($this->cache->getFolderContents('folder')));
+ }
+
public function tearDown() {
$this->cache->clear();
}