summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2014-08-26 10:33:18 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2014-08-26 10:33:18 +0200
commit2e8026a7b598c5df061f324249d632c2306966bc (patch)
tree1f54c170cd569fa44a2a340581a78057b8581a31 /lib
parentc733842a9a4fb34452ecaa49f5f62079046b54de (diff)
parent1846aebfff14971d4c99a04cfe1a90a77c7591ba (diff)
downloadnextcloud-server-2e8026a7b598c5df061f324249d632c2306966bc.tar.gz
nextcloud-server-2e8026a7b598c5df061f324249d632c2306966bc.zip
Merge pull request #10619 from owncloud/issue/6722
Add a test to break the slugifyPath() with folder and file afterwards
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/mapper.php35
1 files changed, 21 insertions, 14 deletions
diff --git a/lib/private/files/mapper.php b/lib/private/files/mapper.php
index 666719da12d..94dda807c2b 100644
--- a/lib/private/files/mapper.php
+++ b/lib/private/files/mapper.php
@@ -177,14 +177,12 @@ class Mapper
/**
* @param integer $index
*/
- public function slugifyPath($path, $index=null) {
+ public function slugifyPath($path, $index = null) {
$path = $this->stripRootFolder($path, $this->unchangedPhysicalRoot);
$pathElements = explode('/', $path);
$sluggedElements = array();
-
- $last= end($pathElements);
-
+
foreach ($pathElements as $pathElement) {
// remove empty elements
if (empty($pathElement)) {
@@ -196,19 +194,18 @@ class Mapper
// apply index to file name
if ($index !== null) {
- $last= array_pop($sluggedElements);
+ $last = array_pop($sluggedElements);
// if filename contains periods - add index number before last period
- if (preg_match('~\.[^\.]+$~i',$last,$extension)){
- array_push($sluggedElements, substr($last,0,-(strlen($extension[0]))).'-'.$index.$extension[0]);
+ if (preg_match('~\.[^\.]+$~i', $last, $extension)) {
+ array_push($sluggedElements, substr($last, 0, -(strlen($extension[0]))) . '-' . $index . $extension[0]);
} else {
// if filename doesn't contain periods add index ofter the last char
- array_push($sluggedElements, $last.'-'.$index);
- }
-
+ array_push($sluggedElements, $last . '-' . $index);
+ }
}
- $sluggedPath = $this->unchangedPhysicalRoot.implode('/', $sluggedElements);
+ $sluggedPath = $this->unchangedPhysicalRoot . implode('/', $sluggedElements);
return $this->stripLast($sluggedPath);
}
@@ -218,8 +215,8 @@ class Mapper
* @param string $text
* @return string
*/
- private function slugify($text)
- {
+ private function slugify($text) {
+ $originalText = $text;
// replace non letter or digits or dots by -
$text = preg_replace('~[^\\pL\d\.]+~u', '-', $text);
@@ -241,7 +238,17 @@ class Mapper
$text = preg_replace('~\.+$~', '', $text);
if (empty($text)) {
- return uniqid();
+ /**
+ * Item slug would be empty. Previously we used uniqid() here.
+ * However this means that the behaviour is not reproducible, so
+ * when uploading files into a "empty" folder, the folders name is
+ * different.
+ *
+ * If there would be a md5() hash collision, the deduplicate check
+ * will spot this and append an index later, so this should not be
+ * a problem.
+ */
+ return md5($originalText);
}
return $text;