From 9708ce15904ea256b544643a712ea0e255133411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 3 Apr 2023 16:56:30 +0200 Subject: [PATCH] fix: Avoid error when browser cannot detect font mimetype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Controller/SettingsController.php | 12 ++++++++++-- src/components/AdminSettings.vue | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 605512a465..c165570ed2 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -39,6 +39,7 @@ class SettingsController extends Controller { public const FONT_MIME_TYPES = [ 'font/ttf', 'application/font-sfnt', + 'font/sfnt', 'font/opentype', 'application/vnd.oasis.opendocument.formula-template', ]; @@ -432,8 +433,15 @@ public function uploadFontFile(): JSONResponse { try { $file = $this->getUploadedFile('fontfile'); if (isset($file['tmp_name'], $file['name'], $file['type'])) { - if (!in_array($file['type'], self::FONT_MIME_TYPES, true)) { - return new JSONResponse(['error' => 'Font type not supported'], Http::STATUS_BAD_REQUEST); + $fileType = $file['type']; + if (function_exists('mime_content_type')) { + $fileType = @mime_content_type($file['tmp_name']); + } + if (!$fileType) { + $fileType = $file['type']; + } + if (!in_array($fileType, self::FONT_MIME_TYPES, true)) { + return new JSONResponse(['error' => 'Font type not supported: ' . $fileType], Http::STATUS_BAD_REQUEST); } $newFileResource = fopen($file['tmp_name'], 'rb'); if ($newFileResource === false) { diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue index 642466d485..af8fc19205 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -716,7 +716,7 @@ export default { // TODO define font format list const files = event.target.files const file = files[0] - if (!fontMimes.includes(file.type)) { + if (file.type !== '' && !fontMimes.includes(file.type)) { showError(t('richdocuments', 'Font format not supported ({mime})', { mime: file.type })) return }