diff --git a/modules/cms/widgets/MediaManager.php b/modules/cms/widgets/MediaManager.php index 2114c47e5..d84e07acb 100644 --- a/modules/cms/widgets/MediaManager.php +++ b/modules/cms/widgets/MediaManager.php @@ -945,6 +945,25 @@ class MediaManager extends WidgetBase } } + /** + * Creates a slug form the string. A modified version of Laravel's Str::slug + * with the main difference that it accepts @-signs + * @param string + * @return string + */ + public static function slug($string) + { + $title = Str::ascii($title); + // Convert all dashes/underscores into separator + $flip = $separator == '-' ? '_' : '-'; + $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); + // Remove all characters that are not the separator, letters, numbers, whitespace or @. + $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s@]+!u', '', mb_strtolower($title)); + // Replace all separator characters and whitespace by a single separator + $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); + return trim($title, $separator); + } + protected function checkUploadPostback() { $fileName = null; @@ -973,7 +992,7 @@ class MediaManager extends WidgetBase * File name contains non-latin characters, attempt to slug the value */ if (!$this->validateFileName($fileName)) { - $fileNameSlug = Str::slug(File::name($fileName), '-'); + $fileNameSlug = static::slug(File::name($fileName), '-'); $fileName = $fileNameSlug.'.'.$extension; } @@ -1001,7 +1020,7 @@ class MediaManager extends WidgetBase protected function validateFileName($name) { - if (!preg_match('/^[0-9a-z\.\s_\-]+$/i', $name)) { + if (!preg_match('/^[0-9a-z@\.\s_\-]+$/i', $name)) { return false; }