Merge pull request #58127 from nextcloud/svg-handling-link-previews

[stable28] chore: Improve SVG handling in link previews
This commit is contained in:
Arthur Schiwon 2026-02-10 22:27:07 +01:00 committed by GitHub
commit 7d9c274dcb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -170,8 +170,14 @@ class LinkReferenceProvider implements IReferenceProvider {
if (in_array($contentType, self::ALLOWED_CONTENT_TYPES, true) && $contentLength < self::MAX_PREVIEW_SIZE) {
$stream = Utils::streamFor($response->getBody());
$bodyStream = new LimitStream($stream, self::MAX_PREVIEW_SIZE, 0);
$content = $bodyStream->getContents();
if ($contentType === 'image/svg+xml' && stripos(html_entity_decode($content, ENT_XML1), 'XSL/Transform') !== false) {
return;
}
$reference->setImageContentType($contentType);
$folder->newFile(md5($reference->getId()), $bodyStream->getContents());
$folder->newFile(md5($reference->getId()), $content);
$reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Reference.preview', ['referenceId' => md5($reference->getId())]));
}
}