]> BookStack Code Mirror - bookstack/commitdiff
Prevented bad duplicate IDs causing major exception
authorDan Brown <redacted>
Mon, 15 Apr 2019 20:20:32 +0000 (21:20 +0100)
committerDan Brown <redacted>
Mon, 15 Apr 2019 20:20:32 +0000 (21:20 +0100)
Related to #1393

app/Entities/Repos/EntityRepo.php
tests/Entity/PageContentTest.php

index 3bf70c327b7538c81cf3073f0e02074675c43b09..88ca1bca6d2cce234a83b13456a7c403733e9327 100644 (file)
@@ -715,6 +715,7 @@ class EntityRepo
             }
 
             $doc = new DOMDocument();
+            libxml_use_internal_errors(true);
             $doc->loadHTML(mb_convert_encoding('<body>'.$matchedPage->html.'</body>', 'HTML-ENTITIES', 'UTF-8'));
             $matchingElem = $doc->getElementById($splitInclude[1]);
             if ($matchingElem === null) {
@@ -730,6 +731,7 @@ class EntityRepo
                     $innerContent .= $doc->saveHTML($childNode);
                 }
             }
+            libxml_clear_errors();
             $html = str_replace($matches[0][$index], trim($innerContent), $html);
         }
 
index 86abadf147a788d63684a8a71a3a616ef3d57766..003d07d4e19c754d2703e3f77409673a0c1d2280 100644 (file)
@@ -143,4 +143,20 @@ class PageContentTest extends TestCase
         $pageView->assertDontSee(htmlentities($script));
     }
 
+    public function test_duplicate_ids_does_not_break_page_render()
+    {
+        $this->asEditor();
+        $pageA = Page::first();
+        $pageB = Page::query()->where('id', '!=', $pageA->id)->first();
+
+        $content = '<ul id="bkmrk-xxx-%28"></ul> <ul id="bkmrk-xxx-%28"></ul>';
+        $pageA->html = $content;
+        $pageA->save();
+
+        $pageB->html = '<ul id="bkmrk-xxx-%28"></ul> <p>{{@'. $pageA->id .'#test}}</p>';
+        $pageB->save();
+
+        $pageView = $this->get($pageB->getUrl());
+        $pageView->assertSuccessful();
+    }
 }