From 5572180311dc69ba195e7e6945570a73395ef9c9 Mon Sep 17 00:00:00 2001 From: Leon Kessler Date: Mon, 26 Oct 2020 15:55:22 +0000 Subject: [PATCH] Fixes #247 numbers in comments can cause php fatal errors. --- src/PHPHtmlParser/Dom/Tag.php | 2 ++ tests/Node/TextTest.php | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/PHPHtmlParser/Dom/Tag.php b/src/PHPHtmlParser/Dom/Tag.php index 29b68bf..2aeb6aa 100644 --- a/src/PHPHtmlParser/Dom/Tag.php +++ b/src/PHPHtmlParser/Dom/Tag.php @@ -329,6 +329,8 @@ public function makeOpeningTag() } catch (AttributeNotFoundException $e) { // attribute that was in the array not found in the array... let's continue. continue; + } catch (\TypeError $e) { + $val = null; } $val = $attributeDTO->getValue(); if (\is_null($val)) { diff --git a/tests/Node/TextTest.php b/tests/Node/TextTest.php index 44298fc..ce7f0f5 100755 --- a/tests/Node/TextTest.php +++ b/tests/Node/TextTest.php @@ -4,6 +4,7 @@ use PHPHtmlParser\Dom; use PHPHtmlParser\Dom\Node\TextNode; +use PHPHtmlParser\Options; use PHPUnit\Framework\TestCase; use stringEncode\Encode; @@ -74,4 +75,14 @@ public function testSetTextEncoded() $node->setText('biz baz'); $this->assertEquals('biz baz', $node->text()); } + + public function testCommentWithNumbers() { + $dom = new Dom; + $options = new Options(); + $options->setCleanupInput(false); + $dom->setOptions($options); + $dom->loadStr(''); + $output = $dom->outerHtml; + $this->assertContains('', $output); + } }