$html = '<body>' . $html . '</body>';
libxml_use_internal_errors(true);
$doc = new DOMDocument();
- $doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
+ $doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_SCHEMA_CREATE);
$xPath = new DOMXPath($doc);
// Apply to scripts
$returnHtml = '';
$topElems = $doc->documentElement->childNodes->item(0)->childNodes;
foreach ($topElems as $child) {
- $returnHtml .= $doc->saveHTML($child);
+ $content = $doc->saveHTML($child);
+ $returnHtml .= $content;
}
return $returnHtml;
--- /dev/null
+<?php
+
+namespace Tests\Settings;
+
+use Tests\TestCase;
+
+class CustomHeadContentTest extends TestCase
+{
+
+ public function test_configured_content_shows_on_pages()
+ {
+ $this->setSettings(['app-custom-head' => '<script>console.log("cat");</script>']);
+ $resp = $this->get('/login');
+ $resp->assertSee('console.log("cat")');
+ }
+
+ public function test_configured_content_does_not_show_on_settings_page()
+ {
+ $this->setSettings(['app-custom-head' => '<script>console.log("cat");</script>']);
+ $resp = $this->asAdmin()->get('/settings');
+ $resp->assertDontSee('console.log("cat")');
+ }
+
+ public function test_divs_in_js_preserved_in_configured_content()
+ {
+ $this->setSettings(['app-custom-head' => '<script><div id="hello">cat</div></script>']);
+ $resp = $this->get('/login');
+ $resp->assertSee('<div id="hello">cat</div>');
+ }
+}
\ No newline at end of file