Skip to content

Commit 21eeaf0

Browse files
committed
prevent infinite loop on unterminated entity declaration at end of stream
1 parent 104443a commit 21eeaf0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/HTML5/Parser/Tokenizer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,13 @@ protected function decodeCharacterReference($inAttribute = false)
11111111
if ('#' === $tok) {
11121112
$tok = $this->scanner->next();
11131113

1114+
if (false === $tok) {
1115+
$this->parseError('Expected &#DEC; &#HEX;, got EOF');
1116+
$this->scanner->unconsume(1);
1117+
1118+
return '&';
1119+
}
1120+
11141121
// Hexidecimal encoding.
11151122
// X[0-9a-fA-F]+;
11161123
// x[0-9a-fA-F]+;

test/HTML5/Parser/DOMTreeBuilderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ public function testBareAmpersandNotAllowedInBody()
133133
</html>', $doc->saveXML());
134134
}
135135

136+
public function testEntityAtEndOfFile()
137+
{
138+
$fragment = $this->parseFragment('&#');
139+
$this->assertInstanceOf('DOMDocumentFragment', $fragment);
140+
$this->assertSame('&#', $fragment->textContent);
141+
$this->assertEquals('Line 1, Col 2: Expected &#DEC; &#HEX;, got EOF', $this->errors[0]);
142+
}
143+
136144
public function testStrangeCapitalization()
137145
{
138146
$html = '<!doctype html>

0 commit comments

Comments
 (0)