From: Dan Brown Date: Tue, 24 May 2022 17:05:47 +0000 (+0100) Subject: Replaced embeds with images in exports X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/refs/pull/3452/head?ds=inline Replaced embeds with images in exports --- diff --git a/app/Entities/Tools/ExportFormatter.php b/app/Entities/Tools/ExportFormatter.php index ed3e8d326..cda8e0308 100644 --- a/app/Entities/Tools/ExportFormatter.php +++ b/app/Entities/Tools/ExportFormatter.php @@ -215,9 +215,12 @@ class ExportFormatter */ protected function containHtml(string $htmlContent): string { + // Replace embed tags with images + $htmlContent = preg_replace("//i", '', $htmlContent); + // Replace image & embed src attributes with base64 encoded data strings $imageTagsOutput = []; - preg_match_all("/<(?:img|embed) .*?src=['\"](.*?)['\"].*?>/i", $htmlContent, $imageTagsOutput); + preg_match_all("//i", $htmlContent, $imageTagsOutput); if (isset($imageTagsOutput[0]) && count($imageTagsOutput[0]) > 0) { foreach ($imageTagsOutput[0] as $index => $imgMatch) { $oldImgTagString = $imgMatch; diff --git a/tests/Entity/ExportTest.php b/tests/Entity/ExportTest.php index 9debec12b..015fab5c3 100644 --- a/tests/Entity/ExportTest.php +++ b/tests/Entity/ExportTest.php @@ -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 = ''; @@ -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('', false); + $resp->assertSee('', false); } public function test_exports_removes_scripts_from_custom_head()