From 2b05d01c6ca2fc5e0a582a2b71bff3b75b9da960 Mon Sep 17 00:00:00 2001 From: Larry Barker Date: Thu, 5 Dec 2019 02:44:04 -0600 Subject: [PATCH] Support additional file name and path characters in media manager (#4564) * Support additional file name and path characters in media manager When working with abstract file names that may contain additional characters, such as quotes or ampersands, the media manager would throw an error. This PR adds two additional characters to the character whitelist. * Add unicode filename to tests --- modules/system/classes/MediaLibrary.php | 2 ++ tests/unit/system/classes/MediaLibraryTest.php | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/modules/system/classes/MediaLibrary.php b/modules/system/classes/MediaLibrary.php index 645825750..93b6fe58f 100644 --- a/modules/system/classes/MediaLibrary.php +++ b/modules/system/classes/MediaLibrary.php @@ -486,6 +486,8 @@ class MediaLibrary preg_quote(']', '/'), preg_quote(',', '/'), preg_quote('=', '/'), + preg_quote("'", '/'), + preg_quote('&', '/'), ]; if (!preg_match('/^[' . implode('', $regexWhitelist) . ']+$/iu', $path)) { diff --git a/tests/unit/system/classes/MediaLibraryTest.php b/tests/unit/system/classes/MediaLibraryTest.php index 55c027544..24bab1567 100644 --- a/tests/unit/system/classes/MediaLibraryTest.php +++ b/tests/unit/system/classes/MediaLibraryTest.php @@ -37,6 +37,11 @@ class MediaLibraryTest extends TestCase // @codingStandardsIgnoreLine ['one(two)[].ext'], ['one=(two)[].ext'], ['one_(two)[].ext'], + /* + Example of a unicode-based filename with a single quote + @see: https://github.com/octobercms/october/pull/4564 + */ + ['BG中国通讯期刊(Blend\'r)创刊号.pdf'], ]; }