]> BookStack Code Mirror - bookstack/commitdiff
Fixed issue where page export contain system would miss images
authorDan Brown <redacted>
Sun, 6 Dec 2020 22:23:21 +0000 (22:23 +0000)
committerDan Brown <redacted>
Sun, 6 Dec 2020 22:23:21 +0000 (22:23 +0000)
app/Entities/Tools/ExportFormatter.php
tests/Entity/ExportTest.php

index 92469a9b04090cc51920dcff53acd6fe727aadc6..9cf8b56af2476458d51316044662f6f1e8156e96 100644 (file)
@@ -143,7 +143,7 @@ class ExportFormatter
     protected function containHtml(string $htmlContent): string
     {
         $imageTagsOutput = [];
-        preg_match_all("/\<img.*src\=(\'|\")(.*?)(\'|\").*?\>/i", $htmlContent, $imageTagsOutput);
+        preg_match_all("/\<img.*?src\=(\'|\")(.*?)(\'|\").*?\>/i", $htmlContent, $imageTagsOutput);
 
         // Replace image src with base64 encoded image strings
         if (isset($imageTagsOutput[0]) && count($imageTagsOutput[0]) > 0) {
index 7c56a7268aead1f91817b3d17274cd456e73d255..1e44f015a5a0b69f8520c9227b971e79f17c0b63 100644 (file)
@@ -167,12 +167,28 @@ class ExportTest extends TestCase
         $resp->assertSee('<img src="data:image/svg+xml;base64');
     }
 
+    public function test_page_image_containment_works_on_multiple_images_within_a_single_line()
+    {
+        $page = Page::first();
+        Storage::disk('local')->makeDirectory('uploads/images/gallery');
+        Storage::disk('local')->put('uploads/images/gallery/svg_test.svg', '<svg></svg>');
+        Storage::disk('local')->put('uploads/images/gallery/svg_test2.svg', '<svg></svg>');
+        $page->html = '<img src="http://localhost/uploads/images/gallery/svg_test.svg" class="a"><img src="http://localhost/uploads/images/gallery/svg_test2.svg" class="b">';
+        $page->save();
+
+        $resp = $this->asEditor()->get($page->getUrl('/export/html'));
+        Storage::disk('local')->delete('uploads/images/gallery/svg_test.svg');
+        Storage::disk('local')->delete('uploads/images/gallery/svg_test2.svg');
+
+        $resp->assertDontSee('http://localhost/uploads/images/gallery/svg_test');
+    }
+
     public function test_page_export_contained_html_image_fetches_only_run_when_url_points_to_image_upload_folder()
     {
         $page = Page::first();
         $page->html = '<img src="http://localhost/uploads/images/gallery/svg_test.svg"/>'
-            ."\n".'<img src="http://localhost/uploads/svg_test.svg"/>'
-            ."\n".'<img src="/uploads/svg_test.svg"/>';
+            .'<img src="http://localhost/uploads/svg_test.svg"/>'
+            .'<img src="/uploads/svg_test.svg"/>';
         $storageDisk = Storage::disk('local');
         $storageDisk->makeDirectory('uploads/images/gallery');
         $storageDisk->put('uploads/images/gallery/svg_test.svg', '<svg>good</svg>');