Relax restrictions on MediaLibrary filenames (#3778)

Fixes #3741. Credit to @chrisbethelepb
This commit is contained in:
chrisbethelepb 2018-09-12 13:37:21 -04:00 committed by Luke Towers
parent cf9d487b30
commit 0ffdbc5efd
2 changed files with 24 additions and 4 deletions

View File

@ -475,7 +475,23 @@ class MediaLibrary
/*
* Validate folder names
*/
if (!preg_match('/^[\w@\.\s_\-\/]+$/iu', $path)) {
$regexWhitelist = [
'\w', // any word character
preg_quote('@', '/'),
preg_quote('.', '/'),
'\s', // whitespace character
preg_quote('-', '/'),
preg_quote('_', '/'),
preg_quote('/', '/'),
preg_quote('(', '/'),
preg_quote(')', '/'),
preg_quote('[', '/'),
preg_quote(']', '/'),
preg_quote(',', '/'),
preg_quote('=', '/'),
];
if (!preg_match('/^[' . implode('', $regexWhitelist) . ']+$/iu', $path)) {
throw new ApplicationException(Lang::get('system::lang.media.invalid_path', compact('path')));
}

View File

@ -33,6 +33,10 @@ class MediaLibraryTest extends TestCase // @codingStandardsIgnoreLine
['file.ext'],
['file..ext'],
['file...ext'],
['one,two.ext'],
['one(two)[].ext'],
['one=(two)[].ext'],
['one_(two)[].ext'],
];
}