From 9cfbf7ed1c92b262984488eaa9cee5df88419d5b Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 16 Oct 2014 12:13:16 +0200 Subject: [PATCH] Fix SVG icons FIXME: Ugly hack to prevent SVG of being returned if the SVG provider is not enabled. This is required because the preview system is designed in a bad way and relies on opt-in with asterisks (i.e. image/*) which will lead to the fact that a SVG will also match the image provider. Conflicts: lib/private/preview.php --- apps/files_sharing/js/public.js | 2 +- lib/private/preview.php | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index b3036254401..c4b5508692e 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -85,7 +85,7 @@ OCA.Sharing.PublicApp = { }; var img = $(''); - if (previewSupported === 'true' || mimetype.substr(0, mimetype.indexOf('/')) === 'image') { + if (previewSupported === 'true' || mimetype.substr(0, mimetype.indexOf('/')) === 'image' && mimetype !== 'image/svg+xml') { img.attr('src', OC.filePath('files_sharing', 'ajax', 'publicpreview.php') + '?' + OC.buildQueryString(params)); img.appendTo('#imgframe'); } else if (mimetype.substr(0, mimetype.indexOf('/')) !== 'video') { diff --git a/lib/private/preview.php b/lib/private/preview.php index e9bfb3b9285..00f18219531 100755 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -814,8 +814,19 @@ class Preview { self::initProviders(); } - foreach (self::$providers as $supportedMimeType => $provider) { - if (preg_match($supportedMimeType, $mimeType)) { + // FIXME: Ugly hack to prevent SVG of being returned if the SVG + // provider is not enabled. + // This is required because the preview system is designed in a + // bad way and relies on opt-in with asterisks (i.e. image/*) + // which will lead to the fact that a SVG will also match the image + // provider. + if($mimeType === 'image/svg+xml' && !array_key_exists('/image\/svg\+xml/', self::$providers)) { + return false; + } + + //remove last element because it has the mimetype * + foreach(self::$providers as $supportedMimetype => $provider) { + if(preg_match($supportedMimetype, $mimeType)) { return true; } } -- 2.39.5