diff --git a/src/HTML5/Parser/Tokenizer.php b/src/HTML5/Parser/Tokenizer.php index 0699cf1..9e237fd 100644 --- a/src/HTML5/Parser/Tokenizer.php +++ b/src/HTML5/Parser/Tokenizer.php @@ -126,26 +126,25 @@ protected function consumeData() // Parse tag if ('<' === $tok) { - // Any buffered text data can go out now. - $this->flushBuffer(); - $tok = $this->scanner->next(); - if (false === $tok) { - // end of string - $this->parseError('Illegal tag opening'); - } elseif ('!' === $tok) { + if ('!' === $tok) { + $this->flushBuffer(); $this->markupDeclaration(); } elseif ('/' === $tok) { + $this->flushBuffer(); $this->endTag(); } elseif ('?' === $tok) { + $this->flushBuffer(); $this->processingInstruction(); } elseif ($this->is_alpha($tok)) { + $this->flushBuffer(); $this->tagName(); } else { $this->parseError('Illegal tag opening'); - // TODO is this necessary ? - $this->characterData(); + $this->text('<'); + $this->scanner->unconsume(); + return; } $tok = $this->scanner->current(); diff --git a/test/HTML5/Html5Test.php b/test/HTML5/Html5Test.php index 7c2f485..b5474d4 100644 --- a/test/HTML5/Html5Test.php +++ b/test/HTML5/Html5Test.php @@ -505,6 +505,9 @@ public function testUnescaped() $res = $this->cycleFragment(''); $this->assertRegExp('|div>div>div|', $res); + + $res = $this->cycleFragment('

There is a less-than character after this word < is it rendered?

'); + $this->assertRegExp('|

There is a less-than character after this word < is it rendered\\?

|', $res); } public function testEntities() diff --git a/test/HTML5/Parser/TokenizerTest.php b/test/HTML5/Parser/TokenizerTest.php index c9643c5..03ce77a 100644 --- a/test/HTML5/Parser/TokenizerTest.php +++ b/test/HTML5/Parser/TokenizerTest.php @@ -526,7 +526,7 @@ public function testTagNotClosedAfterTagName() $this->assertEventError($events->get(0)); $this->assertEventEquals('startTag', 'span', $events->get(1)); $this->assertEventError($events->get(2)); - $this->assertEventEquals('text', '>02', $events->get(3)); + $this->assertEventEquals('text', '<>02', $events->get(3)); $this->assertEventEquals('endTag', 'span', $events->get(4)); $this->assertEventEquals('eof', null, $events->get(5)); @@ -957,6 +957,16 @@ public function testText() $events = $this->parse('a²b'); $this->assertEquals(2, $events->depth(), 'Events: ' . print_r($events, true)); $this->assertEventEquals('text', 'a²b', $events->get(0)); + + $events = $this->parse('a < b'); + $this->assertEquals(3, $events->depth(), 'Events: ' . print_r($events, true)); + $this->assertEventError($events->get(0)); + $this->assertEventEquals('text', 'a < b', $events->get(1)); + + $events = $this->parse('a <'); + $this->assertEquals(3, $events->depth(), 'Events: ' . print_r($events, true)); + $this->assertEventError($events->get(0)); + $this->assertEventEquals('text', 'a <', $events->get(1)); } // ================================================================