diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index da27b48b6f6..6f72c1422bf 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -8,6 +8,7 @@ ### Fixed - Fixed a bug where Craft could auto-place the `{{ beginBody() }}` and `{{ endBody() }}` tags in the wrong places. - Fixed a bug where Craft wasn’t storing custom volume sort orders. ([#3764](https://github.com/craftcms/cms/issues/3764)) +- Fixed a SQL error that would occur when uploading a file with emojis in its name, if using MySQL. ([#3852](https://github.com/craftcms/cms/issues/3852)) ## 3.1.12 - 2019-02-15 diff --git a/src/helpers/FileHelper.php b/src/helpers/FileHelper.php index 43e0a61a1ce..78d61192d57 100644 --- a/src/helpers/FileHelper.php +++ b/src/helpers/FileHelper.php @@ -171,6 +171,11 @@ public static function sanitizeFilename(string $filename, array $options = []): // Strip any characters not allowed. $filename = str_replace($disallowedChars, '', strip_tags($filename)); + if (Craft::$app->getDb()->getIsMysql()) { + // Strip emojis + $filename = StringHelper::replaceMb4($filename, ''); + } + if ($separator !== null) { $filename = preg_replace('/(\s|' . preg_quote($separator, '/') . ')+/u', $separator, $filename); }