diff --git a/src/Entity/Attachments/Attachment.php b/src/Entity/Attachments/Attachment.php index eb931609..f27b0e70 100644 --- a/src/Entity/Attachments/Attachment.php +++ b/src/Entity/Attachments/Attachment.php @@ -144,9 +144,17 @@ abstract class Attachment extends AbstractNamedDBElement */ public function isPicture(): bool { - //We can not check if an external link is a picture, so just assume this is false if ($this->isExternal()) { - return true; + //Check if we can extract a file extension from the URL + $extension = pathinfo(parse_url($this->path, PHP_URL_PATH) ?? '', PATHINFO_EXTENSION); + + //If no extension is found or it is known picture extension, we assume that this is a picture extension + if ($extension === '' || in_array(strtolower($extension), static::PICTURE_EXTS, true)) { + return true; + } + + //Otherwise we assume that the file is not a picture + return false; } $extension = pathinfo($this->getPath(), PATHINFO_EXTENSION); diff --git a/tests/Entity/Attachments/AttachmentTest.php b/tests/Entity/Attachments/AttachmentTest.php index ef10dc24..8d116398 100644 --- a/tests/Entity/Attachments/AttachmentTest.php +++ b/tests/Entity/Attachments/AttachmentTest.php @@ -182,8 +182,11 @@ class AttachmentTest extends TestCase return [ ['%MEDIA%/foo/bar.txt', false], ['https://test.de/picture.jpeg', true], + ['https://test.de/picture.png?test=fdsj&width=34', true], + ['https://invalid.invalid/file.txt', false], + ['http://infsf.inda/file.zip?test', false], ['https://test.de', true], - ['http://test.de/google.de', true], + ['https://invalid.com/invalid/pic', true], ['%MEDIA%/foo/bar.jpeg', true], ['%MEDIA%/foo/bar.webp', true], ['%MEDIA%/foo', false],