Skip to content

Fixes #247 numbers in comments can cause php fatal errors. #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}