Skip to content

Commit 3b47c9d

Browse files
committed
Merge branch 'fixed-cdata-parsing' of git://github.com/onlinesid/php-html-parser into onlinesid-fixed-cdata-parsing
2 parents 1d4e379 + eb2a3f9 commit 3b47c9d

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Added
1414
- Added support for PSR7 HTTP clients and requests for URL calls.
15+
- Added PHAN support and fixed all issues from PHAN.
1516

1617
### Changed
1718
- Fixed issue with \ causing an infite loop.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PHP Html Parser
22
==========================
33

4-
Version 2.2.0
4+
Version 2.2.1
55

66
[![Build Status](https://travis-ci.org/paquettg/php-html-parser.png)](https://travis-ci.org/paquettg/php-html-parser)
77
[![Coverage Status](https://coveralls.io/repos/paquettg/php-html-parser/badge.png)](https://coveralls.io/r/paquettg/php-html-parser)

src/PHPHtmlParser/Dom.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,13 @@ protected function parse(): void
615615
$this->root->setHtmlSpecialCharsDecode($this->options->htmlSpecialCharsDecode);
616616
$activeNode = $this->root;
617617
while (!\is_null($activeNode)) {
618-
$str = $this->content->copyUntil('<');
618+
if ($activeNode && $activeNode->tag->name() === 'script'
619+
&& $this->options->get('cleanupInput') != true
620+
) {
621+
$str = $this->content->copyUntil('</');
622+
} else {
623+
$str = $this->content->copyUntil('<');
624+
}
619625
if ($str == '') {
620626
$info = $this->parseTag();
621627
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)