]> BookStack Code Mirror - bookstack/commitdiff
Replaced embeds with images in exports svg_image 3452/head
authorDan Brown <redacted>
Tue, 24 May 2022 17:05:47 +0000 (18:05 +0100)
committerDan Brown <redacted>
Tue, 24 May 2022 17:05:47 +0000 (18:05 +0100)
app/Entities/Tools/ExportFormatter.php
tests/Entity/ExportTest.php

index ed3e8d326f693c290eafba1c387b06b0abc27e55..cda8e0308892259b95aa206ca01d3cf44a19143a 100644 (file)
@@ -215,9 +215,12 @@ class ExportFormatter
      */
     protected function containHtml(string $htmlContent): string
     {
+        // Replace embed tags with images
+        $htmlContent = preg_replace("/<embed (.*?)>/i", '<img $1>', $htmlContent);
+
         // Replace image & embed src attributes with base64 encoded data strings
         $imageTagsOutput = [];
-        preg_match_all("/<(?:img|embed) .*?src=['\"](.*?)['\"].*?>/i", $htmlContent, $imageTagsOutput);
+        preg_match_all("/<img .*?src=['\"](.*?)['\"].*?>/i", $htmlContent, $imageTagsOutput);
         if (isset($imageTagsOutput[0]) && count($imageTagsOutput[0]) > 0) {
             foreach ($imageTagsOutput[0] as $index => $imgMatch) {
                 $oldImgTagString = $imgMatch;
index 9debec12bdc3b9c9980853548ae8555436eaced1..015fab5c3641ecd5351b761aed5b686ffa6c7303 100644 (file)
@@ -258,7 +258,7 @@ class ExportTest extends TestCase
         unlink($testFilePath);
     }
 
-    public function test_page_export_contained_html_embed_element_srcs_are_inlined()
+    public function test_page_export_contained_html_embed_elements_are_converted_to_images_with_srcs_inlined()
     {
         $page = Page::query()->first();
         $page->html = '<embed src="http://localhost/uploads/images/gallery/svg_test.svg"/>';
@@ -273,7 +273,7 @@ class ExportTest extends TestCase
         $storageDisk->delete('uploads/images/gallery/svg_test.svg');
 
         $resp->assertDontSee('http://localhost/uploads/images/gallery/svg_test.svg', false);
-        $resp->assertSee('<embed src="data:image/svg+xml;base64,PHN2Zz5nb29kPC9zdmc+">', false);
+        $resp->assertSee('<img src="data:image/svg+xml;base64,PHN2Zz5nb29kPC9zdmc+">', false);
     }
 
     public function test_exports_removes_scripts_from_custom_head()