diff options
author | infoneo <infoneo@yahoo.pl> | 2013-05-12 01:47:48 +0200 |
---|---|---|
committer | infoneo <infoneo@yahoo.pl> | 2013-05-12 01:47:48 +0200 |
commit | 8f19c5ecab7058702882aa3db4d3202ca697cb70 (patch) | |
tree | 2167e287a9bcb1d183c4b11b5793495eed6e150d | |
parent | 8a838e0e03501fd0230ae1e843f53213331d2c55 (diff) | |
download | nextcloud-server-8f19c5ecab7058702882aa3db4d3202ca697cb70.tar.gz nextcloud-server-8f19c5ecab7058702882aa3db4d3202ca697cb70.zip |
Dots in a filenames fix
-rw-r--r-- | lib/files/mapper.php | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/files/mapper.php b/lib/files/mapper.php index 15f5f0628b5..97a2bff915a 100644 --- a/lib/files/mapper.php +++ b/lib/files/mapper.php @@ -172,13 +172,21 @@ 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); + + if ((preg_match('~[-\w]+~', $parts['filename'])) && (preg_match('~[-\w]+~', $parts['extension']))){ + + // rip off the extension ext from last element + $filename = $parts['filename']; + array_pop($pathElements); + array_push($pathElements, $filename); + + } else { + + unset($parts['extension']); + } foreach ($pathElements as $pathElement) { // remove empty elements @@ -213,8 +221,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 +236,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(); |