Skip to content

Commit 79730ce

Browse files
authored
Merge pull request paquettg#249 from leonk/master-fix-comments-with-numbers
Fixes paquettg#247 numbers in comments can cause php fatal errors.
2 parents f5c2dd9 + 5572180 commit 79730ce

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/PHPHtmlParser/Dom/Tag.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ public function makeOpeningTag()
329329
} catch (AttributeNotFoundException $e) {
330330
// attribute that was in the array not found in the array... let's continue.
331331
continue;
332+
} catch (\TypeError $e) {
333+
$val = null;
332334
}
333335
$val = $attributeDTO->getValue();
334336
if (\is_null($val)) {

tests/Node/TextTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPHtmlParser\Dom;
66
use PHPHtmlParser\Dom\Node\TextNode;
7+
use PHPHtmlParser\Options;
78
use PHPUnit\Framework\TestCase;
89
use stringEncode\Encode;
910

@@ -74,4 +75,14 @@ public function testSetTextEncoded()
7475
$node->setText('biz baz');
7576
$this->assertEquals('biz baz', $node->text());
7677
}
78+
79+
public function testCommentWithNumbers() {
80+
$dom = new Dom;
81+
$options = new Options();
82+
$options->setCleanupInput(false);
83+
$dom->setOptions($options);
84+
$dom->loadStr('<!-- test comment with number 2 -->');
85+
$output = $dom->outerHtml;
86+
$this->assertContains('<!-- test comment with number 2 -->', $output);
87+
}
7788
}

0 commit comments

Comments
 (0)