Skip to content

Commit

Permalink
Merge pull request #249 from leonk/master-fix-comments-with-numbers
Browse files Browse the repository at this point in the history
Fixes #247 numbers in comments can cause php fatal errors.
  • Loading branch information
paquettg authored Nov 1, 2020
2 parents f5c2dd9 + 5572180 commit 79730ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/PHPHtmlParser/Dom/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
11 changes: 11 additions & 0 deletions tests/Node/TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPHtmlParser\Dom;
use PHPHtmlParser\Dom\Node\TextNode;
use PHPHtmlParser\Options;
use PHPUnit\Framework\TestCase;
use stringEncode\Encode;

Expand Down Expand Up @@ -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('<!-- test comment with number 2 -->');
$output = $dom->outerHtml;
$this->assertContains('<!-- test comment with number 2 -->', $output);
}
}

0 comments on commit 79730ce

Please sign in to comment.