Skip to content

Commit

Permalink
Prevented bad duplicate IDs causing major exception
Browse files Browse the repository at this point in the history
Related to #1393
  • Loading branch information
ssddanbrown committed Apr 15, 2019
1 parent 95d4149 commit c380c10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/Entities/Repos/EntityRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ protected function parsePageIncludes(string $html) : string
}

$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) {
Expand All @@ -730,6 +731,7 @@ protected function parsePageIncludes(string $html) : string
$innerContent .= $doc->saveHTML($childNode);
}
}
libxml_clear_errors();
$html = str_replace($matches[0][$index], trim($innerContent), $html);
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Entity/PageContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,20 @@ public function test_page_content_scripts_show_when_configured()
$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();
}
}

0 comments on commit c380c10

Please sign in to comment.