LinkTransformer: Use a more reliable extention detection

This commit is contained in:
Johannes Meyer 2022-02-04 12:48:16 +01:00
parent 8f4a0c62d5
commit baf2f1bbde
1 changed files with 5 additions and 2 deletions

View File

@ -5,7 +5,6 @@ namespace Icinga\Web\Helper\Markdown;
use HTMLPurifier_AttrTransform;
use HTMLPurifier_Config;
use ipl\Stdlib\Str;
use ipl\Web\Url;
class LinkTransformer extends HTMLPurifier_AttrTransform
@ -48,8 +47,12 @@ class LinkTransformer extends HTMLPurifier_AttrTransform
}
$url = Url::fromPath($attr['href']);
$fileName = basename($url->getPath());
list($_, $ext) = Str::symmetricSplit($url->getPath(), '.', 2);
$ext = null;
if (($extAt = strrpos($fileName, '.')) !== false) {
$ext = substr($fileName, $extAt + 1);
}
$hasThumbnail = $ext !== null && in_array($ext, static::$IMAGE_FILES, true);
$useIframe = $ext !== null && ! in_array($ext, static::$NON_IFRAME_FILES, true);