From 88431be37966f89f2a96210ee855565212f34969 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 24 Nov 2018 13:53:53 +0100 Subject: Optimize the parsing of unquoted attributes --- src/HTML5/Parser/Tokenizer.php | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src/HTML5/Parser') diff --git a/src/HTML5/Parser/Tokenizer.php b/src/HTML5/Parser/Tokenizer.php index 6284733..49f5fc0 100644 --- a/src/HTML5/Parser/Tokenizer.php +++ b/src/HTML5/Parser/Tokenizer.php @@ -594,19 +594,37 @@ class Tokenizer protected function unquotedAttributeValue() { - $stoplist = "\t\n\f >"; $val = ''; $tok = $this->scanner->current(); - while (0 == strspn($tok, $stoplist) && false !== $tok) { - if ('&' == $tok) { - $val .= $this->decodeCharacterReference(true); - $tok = $this->scanner->current(); - } else { - if (strspn($tok, "\"'<=`") > 0) { + while (false !== $tok) { + switch ($tok) { + case "\n": + case "\f": + case ' ': + case "\t": + case '>': + break 2; + + case '&': + $val .= $this->decodeCharacterReference(true); + $tok = $this->scanner->current(); + + break; + + case "'": + case '"': + case '<': + case '=': + case '`': $this->parseError('Unexpected chars in unquoted attribute value %s', $tok); - } - $val .= $tok; - $tok = $this->scanner->next(); + $val .= $tok; + $tok = $this->scanner->next(); + break; + + default: + $val .= $this->scanner->charsUntil("\t\n\f >&\"'<=`"); + + $tok = $this->scanner->current(); } } -- cgit v1.2.3