Skip to content

Commit

Permalink
Merge pull request #2934 from nextcloud/backport/2893/stable25
Browse files Browse the repository at this point in the history
  • Loading branch information
juliushaertl committed May 8, 2023
2 parents 94f92a4 + 9708ce1 commit b46264d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/Controller/SettingsController.php
Expand Up @@ -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',
];
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/AdminSettings.vue
Expand Up @@ -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
}
Expand Down

0 comments on commit b46264d

Please sign in to comment.