Skip to content

Commit

Permalink
prevent infinite loop on unterminated entity declaration at end of st…
Browse files Browse the repository at this point in the history
…ream
  • Loading branch information
goetas committed Feb 6, 2020
1 parent 104443a commit 21eeaf0
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 21eeaf0

Please sign in to comment.