From c380c10d54b96ae3f2f4c1c4ba7fbf1822f3b945 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 15 Apr 2019 21:20:32 +0100 Subject: [PATCH] Prevented bad duplicate IDs causing major exception Related to #1393 --- app/Entities/Repos/EntityRepo.php | 2 ++ tests/Entity/PageContentTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/Entities/Repos/EntityRepo.php b/app/Entities/Repos/EntityRepo.php index 3bf70c327..88ca1bca6 100644 --- a/app/Entities/Repos/EntityRepo.php +++ b/app/Entities/Repos/EntityRepo.php @@ -715,6 +715,7 @@ class EntityRepo } $doc = new DOMDocument(); + libxml_use_internal_errors(true); $doc->loadHTML(mb_convert_encoding(''.$matchedPage->html.'', '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); } diff --git a/tests/Entity/PageContentTest.php b/tests/Entity/PageContentTest.php index 86abadf14..003d07d4e 100644 --- a/tests/Entity/PageContentTest.php +++ b/tests/Entity/PageContentTest.php @@ -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 = ' '; + $pageA->html = $content; + $pageA->save(); + + $pageB->html = '

{{@'. $pageA->id .'#test}}

'; + $pageB->save(); + + $pageView = $this->get($pageB->getUrl()); + $pageView->assertSuccessful(); + } }