Skip to content

Commit

Permalink
Merge pull request #178 from Masterminds/eof-entity
Browse files Browse the repository at this point in the history
Prevent infinite loop on un-terminated entity declaration at EOF
  • Loading branch information
goetas committed Feb 6, 2020
2 parents 114b913 + 21eeaf0 commit a3edfe5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/HTML5/Parser/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,13 @@ protected function decodeCharacterReference($inAttribute = false)
if ('#' === $tok) {
$tok = $this->scanner->next();

if (false === $tok) {
$this->parseError('Expected &#DEC; &#HEX;, got EOF');
$this->scanner->unconsume(1);

return '&';
}

// Hexidecimal encoding.
// X[0-9a-fA-F]+;
// x[0-9a-fA-F]+;
Expand Down
8 changes: 8 additions & 0 deletions test/HTML5/Parser/DOMTreeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ public function testBareAmpersandNotAllowedInBody()
</html>', $doc->saveXML());
}

public function testEntityAtEndOfFile()
{
$fragment = $this->parseFragment('&#');
$this->assertInstanceOf('DOMDocumentFragment', $fragment);
$this->assertSame('&#', $fragment->textContent);
$this->assertEquals('Line 1, Col 2: Expected &#DEC; &#HEX;, got EOF', $this->errors[0]);
}

public function testStrangeCapitalization()
{
$html = '<!doctype html>
Expand Down

0 comments on commit a3edfe5

Please sign in to comment.