summaryrefslogtreecommitdiffstats
path: root/lib/files
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-06-13 03:34:36 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-06-13 03:34:36 -0700
commit54f3174665262a5d1b1e1135667342b17b5d05b0 (patch)
tree4d0c0069b7acba45b7a1ebcfa7f1f2840df14762 /lib/files
parent2b179ccff00913722a7ded8c58f18bacb62d0713 (diff)
parent199207253e2b02808809b79ef1aa27e050b0aff1 (diff)
downloadnextcloud-server-54f3174665262a5d1b1e1135667342b17b5d05b0.tar.gz
nextcloud-server-54f3174665262a5d1b1e1135667342b17b5d05b0.zip
Merge pull request #3640 from infoneo/master
Folders with multiple periods problem fix
Diffstat (limited to 'lib/files')
-rw-r--r--lib/files/mapper.php32
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/files/mapper.php b/lib/files/mapper.php
index 15f5f0628b5..748b65dc4f1 100644
--- a/lib/files/mapper.php
+++ b/lib/files/mapper.php
@@ -172,14 +172,9 @@ class Mapper
$pathElements = explode('/', $path);
$sluggedElements = array();
-
- // rip off the extension ext from last element
+
$last= end($pathElements);
- $parts = pathinfo($last);
- $filename = $parts['filename'];
- array_pop($pathElements);
- array_push($pathElements, $filename);
-
+
foreach ($pathElements as $pathElement) {
// remove empty elements
if (empty($pathElement)) {
@@ -192,13 +187,15 @@ class Mapper
// apply index to file name
if ($index !== null) {
$last= array_pop($sluggedElements);
- array_push($sluggedElements, $last.'-'.$index);
- }
+
+ // 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]);
+ } else {
+ // if filename doesn't contain periods add index ofter the last char
+ array_push($sluggedElements, $last.'-'.$index);
+ }
- // add back the extension
- if (isset($parts['extension'])) {
- $last= array_pop($sluggedElements);
- array_push($sluggedElements, $last.'.'.$parts['extension']);
}
$sluggedPath = $this->unchangedPhysicalRoot.implode('/', $sluggedElements);
@@ -213,8 +210,8 @@ class Mapper
*/
private function slugify($text)
{
- // replace non letter or digits by -
- $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
+ // replace non letter or digits or dots by -
+ $text = preg_replace('~[^\\pL\d\.]+~u', '-', $text);
// trim
$text = trim($text, '-');
@@ -228,7 +225,10 @@ class Mapper
$text = strtolower($text);
// remove unwanted characters
- $text = preg_replace('~[^-\w]+~', '', $text);
+ $text = preg_replace('~[^-\w\.]+~', '', $text);
+
+ // trim ending dots (for security reasons and win compatibility)
+ $text = preg_replace('~\.+$~', '', $text);
if (empty($text)) {
return uniqid();