mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Comments: Switched to lexical editor
Required a lot of changes to provide at least a decent attempt at proper editor teardown control. Also updates HtmlDescriptionFilter and testing to address issue with bad child iteration which could lead to missed items. Renamed editor version from comments to basic as it'll also be used for item descriptions.
This commit is contained in:
@ -193,13 +193,14 @@ class CommentStoreTest extends TestCase
|
||||
{
|
||||
$page = $this->entities->page();
|
||||
|
||||
$script = '<script>const a = "script";</script><p onclick="1">My lovely comment</p>';
|
||||
$script = '<script>const a = "script";</script><script>const b = "sneakyscript";</script><p onclick="1">My lovely comment</p>';
|
||||
$this->asAdmin()->postJson("/comment/$page->id", [
|
||||
'html' => $script,
|
||||
]);
|
||||
|
||||
$pageView = $this->get($page->getUrl());
|
||||
$pageView->assertDontSee($script, false);
|
||||
$pageView->assertDontSee('sneakyscript', false);
|
||||
$pageView->assertSee('<p>My lovely comment</p>', false);
|
||||
|
||||
$comment = $page->comments()->first();
|
||||
@ -209,6 +210,7 @@ class CommentStoreTest extends TestCase
|
||||
|
||||
$pageView = $this->get($page->getUrl());
|
||||
$pageView->assertDontSee($script, false);
|
||||
$pageView->assertDontSee('sneakyscript', false);
|
||||
$pageView->assertSee('<p>My lovely comment</p><p>updated</p>');
|
||||
}
|
||||
|
||||
@ -216,7 +218,7 @@ class CommentStoreTest extends TestCase
|
||||
{
|
||||
$page = $this->entities->page();
|
||||
Comment::factory()->create([
|
||||
'html' => '<script>superbadscript</script><p onclick="superbadonclick">scriptincommentest</p>',
|
||||
'html' => '<script>superbadscript</script><script>superbadscript</script><p onclick="superbadonclick">scriptincommentest</p>',
|
||||
'entity_type' => 'page', 'entity_id' => $page
|
||||
]);
|
||||
|
||||
@ -229,7 +231,7 @@ class CommentStoreTest extends TestCase
|
||||
public function test_comment_html_is_limited()
|
||||
{
|
||||
$page = $this->entities->page();
|
||||
$input = '<h1>Test</h1><p id="abc" href="beans">Content<a href="#cat" data-a="b">a</a><section>Hello</section></p>';
|
||||
$input = '<h1>Test</h1><p id="abc" href="beans">Content<a href="#cat" data-a="b">a</a><section>Hello</section><section>there</section></p>';
|
||||
$expected = '<p>Content<a href="#cat">a</a></p>';
|
||||
|
||||
$resp = $this->asAdmin()->post("/comment/{$page->id}", ['html' => $input]);
|
||||
@ -248,4 +250,27 @@ class CommentStoreTest extends TestCase
|
||||
'html' => $expected,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_comment_html_spans_are_cleaned()
|
||||
{
|
||||
$page = $this->entities->page();
|
||||
$input = '<p><span class="beans">Hello</span> do you have <span style="white-space: discard;">biscuits</span>?</p>';
|
||||
$expected = '<p><span>Hello</span> do you have <span>biscuits</span>?</p>';
|
||||
|
||||
$resp = $this->asAdmin()->post("/comment/{$page->id}", ['html' => $input]);
|
||||
$resp->assertOk();
|
||||
$this->assertDatabaseHas('comments', [
|
||||
'entity_type' => 'page',
|
||||
'entity_id' => $page->id,
|
||||
'html' => $expected,
|
||||
]);
|
||||
|
||||
$comment = $page->comments()->first();
|
||||
$resp = $this->put("/comment/{$comment->id}", ['html' => $input]);
|
||||
$resp->assertOk();
|
||||
$this->assertDatabaseHas('comments', [
|
||||
'id' => $comment->id,
|
||||
'html' => $expected,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user