1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Fixed content parsing break with line html comment

Fixes issues thrown in custom HMTL head & page content filtering when
the content is comprised of only a single HTML comment.
Adds tests to cover.

For #2804
This commit is contained in:
Dan Brown
2021-06-13 12:53:04 +01:00
parent a8471b2c66
commit b5caaa73b7
4 changed files with 73 additions and 42 deletions

View File

@ -13,8 +13,8 @@ class PageContentTest extends TestCase
public function test_page_includes()
{
$page = Page::first();
$secondPage = Page::where('id', '!=', $page->id)->first();
$page = Page::query()->first();
$secondPage = Page::query()->where('id', '!=', $page->id)->first();
$secondPage->html = "<p id='section1'>Hello, This is a test</p><p id='section2'>This is a second block of content</p>";
$secondPage->save();
@ -42,8 +42,8 @@ class PageContentTest extends TestCase
public function test_saving_page_with_includes()
{
$page = Page::first();
$secondPage = Page::where('id', '!=', $page->id)->first();
$page = Page::query()->first();
$secondPage = Page::query()->where('id', '!=', $page->id)->first();
$this->asEditor();
$includeTag = '{{@' . $secondPage->id . '}}';
@ -60,8 +60,8 @@ class PageContentTest extends TestCase
public function test_page_includes_do_not_break_tables()
{
$page = Page::first();
$secondPage = Page::where('id', '!=', $page->id)->first();
$page = Page::query()->first();
$secondPage = Page::query()->where('id', '!=', $page->id)->first();
$content = '<table id="table"><tbody><tr><td>test</td></tr></tbody></table>';
$secondPage->html = $content;
@ -97,7 +97,7 @@ class PageContentTest extends TestCase
public function test_page_content_scripts_removed_by_default()
{
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
$script = 'abc123<script>console.log("hello-test")</script>abc123';
$page->html = "escape {$script}";
$page->save();
@ -120,7 +120,7 @@ class PageContentTest extends TestCase
];
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
foreach ($checks as $check) {
$page->html = $check;
@ -145,7 +145,7 @@ class PageContentTest extends TestCase
];
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
foreach ($checks as $check) {
$page->html = $check;
@ -171,7 +171,7 @@ class PageContentTest extends TestCase
];
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
foreach ($checks as $check) {
$page->html = $check;
@ -192,7 +192,7 @@ class PageContentTest extends TestCase
];
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
foreach ($checks as $check) {
$page->html = $check;
@ -215,7 +215,7 @@ class PageContentTest extends TestCase
];
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
foreach ($checks as $check) {
$page->html = $check;
@ -232,7 +232,7 @@ class PageContentTest extends TestCase
public function test_page_inline_on_attributes_removed_by_default()
{
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
$script = '<p onmouseenter="console.log(\'test\')">Hello</p>';
$page->html = "escape {$script}";
$page->save();
@ -255,7 +255,7 @@ class PageContentTest extends TestCase
];
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
foreach ($checks as $check) {
$page->html = $check;
@ -271,7 +271,7 @@ class PageContentTest extends TestCase
public function test_page_content_scripts_show_when_configured()
{
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
config()->push('app.allow_content_scripts', 'true');
$script = 'abc123<script>console.log("hello-test")</script>abc123';
@ -286,7 +286,7 @@ class PageContentTest extends TestCase
public function test_page_inline_on_attributes_show_if_configured()
{
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
config()->push('app.allow_content_scripts', 'true');
$script = '<p onmouseenter="console.log(\'test\')">Hello</p>';
@ -301,7 +301,7 @@ class PageContentTest extends TestCase
public function test_duplicate_ids_does_not_break_page_render()
{
$this->asEditor();
$pageA = Page::first();
$pageA = Page::query()->first();
$pageB = Page::query()->where('id', '!=', $pageA->id)->first();
$content = '<ul id="bkmrk-xxx-%28"></ul> <ul id="bkmrk-xxx-%28"></ul>';
@ -318,7 +318,7 @@ class PageContentTest extends TestCase
public function test_duplicate_ids_fixed_on_page_save()
{
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
$content = '<ul id="bkmrk-test"><li>test a</li><li><ul id="bkmrk-test"><li>test b</li></ul></li></ul>';
$pageSave = $this->put($page->getUrl(), [
@ -328,14 +328,14 @@ class PageContentTest extends TestCase
]);
$pageSave->assertRedirect();
$updatedPage = Page::where('id', '=', $page->id)->first();
$updatedPage = Page::query()->where('id', '=', $page->id)->first();
$this->assertEquals(substr_count($updatedPage->html, "bkmrk-test\""), 1);
}
public function test_anchors_referencing_non_bkmrk_ids_rewritten_after_save()
{
$this->asEditor();
$page = Page::first();
$page = Page::query()->first();
$content = '<h1 id="non-standard-id">test</h1><p><a href="#non-standard-id">link</a></p>';
$this->put($page->getUrl(), [
@ -344,7 +344,7 @@ class PageContentTest extends TestCase
'summary' => ''
]);
$updatedPage = Page::where('id', '=', $page->id)->first();
$updatedPage = Page::query()->where('id', '=', $page->id)->first();
$this->assertStringContainsString('id="bkmrk-test"', $updatedPage->html);
$this->assertStringContainsString('href="#bkmrk-test"', $updatedPage->html);
}
@ -484,6 +484,25 @@ class PageContentTest extends TestCase
$pageView->assertElementExists('.page-content p > s');
}
public function test_page_markdown_single_html_comment_saving()
{
$this->asEditor();
$page = Page::query()->first();
$content = '<!-- Test Comment -->';
$this->put($page->getUrl(), [
'name' => $page->name, 'markdown' => $content,
'html' => '', 'summary' => ''
]);
$page->refresh();
$this->assertStringMatchesFormat($content, $page->html);
$pageView = $this->get($page->getUrl());
$pageView->assertStatus(200);
$pageView->assertSee($content);
}
public function test_base64_images_get_extracted_from_page_content()
{
$this->asEditor();