]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: Extend SVG reference check 45342/head
authorJoas Schilling <coding@schilljs.com>
Wed, 15 May 2024 21:38:24 +0000 (23:38 +0200)
committerJoas Schilling <coding@schilljs.com>
Thu, 16 May 2024 08:03:54 +0000 (10:03 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Preview/SVG.php
tests/lib/Preview/SVGTest.php

index fd472083533383c63706614234eccc772502aa23..14bdfc46096ac68983783495a311a8107d7c3cf5 100644 (file)
@@ -53,7 +53,7 @@ class SVG extends ProviderV2 {
                        }
 
                        // Do not parse SVG files with references
-                       if (stripos($content, 'xlink:href') !== false) {
+                       if (preg_match('/["\s](xlink:)?href\s*=/i', $content)) {
                                return null;
                        }
 
index e48018a301b172738fbee78da58906a28e641409..07e96eec9ab652fd43acc16f79a0b984240bfa47 100644 (file)
@@ -43,4 +43,33 @@ class SVGTest extends Provider {
                        $this->markTestSkipped('No SVG provider present');
                }
        }
+
+       public function dataGetThumbnailSVGHref(): array {
+               return [
+                       ['href'],
+                       [' href'],
+                       ["\nhref"],
+                       ['xlink:href'],
+                       [' xlink:href'],
+                       ["\nxlink:href"],
+               ];
+       }
+
+       /**
+        * @dataProvider dataGetThumbnailSVGHref
+        * @requires extension imagick
+        */
+       public function testGetThumbnailSVGHref(string $content): void {
+               $handle = fopen('php://temp', 'w+');
+               fwrite($handle, '<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
+  <image x="0" y="0"' . $content . '="fxlogo.png" height="100" width="100" />
+</svg>');
+               rewind($handle);
+
+               $file = $this->createMock(\OCP\Files\File::class);
+               $file->method('fopen')
+                       ->willReturn($handle);
+
+               self::assertNull($this->provider->getThumbnail($file, 512, 512));
+       }
 }