Skip to content

Commit 8020451

Browse files
committed
Page Content: Better handling for empty content filtering
For #6028
1 parent a8d96fd commit 8020451

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

app/Util/HtmlDocument.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ public function getElementById(string $elementId): ?DOMElement
103103
*/
104104
public function getBody(): DOMNode
105105
{
106-
return $this->document->getElementsByTagName('body')[0];
106+
$bodies = $this->document->getElementsByTagName('body');
107+
108+
if ($bodies->length === 0) {
109+
return new DOMElement('body', '');
110+
}
111+
112+
return $bodies[0];
107113
}
108114

109115
/**

tests/Entity/PageEditorTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,23 @@ public function test_editor_html_content_is_filtered_if_loaded_by_a_different_us
282282
$resp->assertOk();
283283
$resp->assertDontSee('hellotherethisisaturtlemonster', false);
284284
}
285+
286+
public function test_editor_html_filtered_does_not_cause_error_if_empty()
287+
{
288+
$emptyExamples = ['', '<p></p>', '<p>&nbsp;</p>', ' ', "\n"];
289+
$editor = $this->users->editor();
290+
$page = $this->entities->page();
291+
$page->updated_by = $editor->id;
292+
293+
foreach ($emptyExamples as $emptyExample) {
294+
$page->html = $emptyExample;
295+
$page->save();
296+
297+
$resp = $this->asAdmin()->get($page->getUrl('edit'));
298+
$resp->assertOk();
299+
300+
$resp = $this->asAdmin()->get("/ajax/page/{$page->id}");
301+
$resp->assertOk();
302+
}
303+
}
285304
}

0 commit comments

Comments
 (0)