Skip to content

Commit eb2a3f9

Browse files
committed
Fixed parsing, CDATA should not be altered when cleanupInput is set to false
1 parent 668c770 commit eb2a3f9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/PHPHtmlParser/Dom.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,13 @@ protected function parse(): void
623623
$this->root->setHtmlSpecialCharsDecode($this->options->htmlSpecialCharsDecode);
624624
$activeNode = $this->root;
625625
while ( ! is_null($activeNode)) {
626-
$str = $this->content->copyUntil('<');
626+
if ($activeNode && $activeNode->tag->name() === 'script'
627+
&& $this->options->get('cleanupInput') != true
628+
) {
629+
$str = $this->content->copyUntil('</');
630+
} else {
631+
$str = $this->content->copyUntil('<');
632+
}
627633
if ($str == '') {
628634
$info = $this->parseTag();
629635
if ( ! $info['status']) {

tests/DomTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ public function tearDown()
1212
Mockery::close();
1313
}
1414

15+
/**
16+
* <![CDATA[ should not be modified when cleanupInput is set to false
17+
*/
18+
public function testParsingCData()
19+
{
20+
$html = "<script type=\"text/javascript\">/* <![CDATA[ */var et_core_api_spam_recaptcha = '';/* ]]> */</script>";
21+
$dom = new Dom();
22+
$dom->setOptions(['cleanupInput' => false,]);
23+
$dom->load($html);
24+
$this->assertSame($html, $dom->root->outerHtml());
25+
}
26+
1527
public function testLoad()
1628
{
1729
$dom = new Dom;

0 commit comments

Comments
 (0)