Skip to content

Commit 88431be

Browse files
committed
Optimize the parsing of unquoted attributes
1 parent 54d066b commit 88431be

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/HTML5/Parser/Tokenizer.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -594,19 +594,37 @@ protected function quotedAttributeValue($quote)
594594

595595
protected function unquotedAttributeValue()
596596
{
597-
$stoplist = "\t\n\f >";
598597
$val = '';
599598
$tok = $this->scanner->current();
600-
while (0 == strspn($tok, $stoplist) && false !== $tok) {
601-
if ('&' == $tok) {
602-
$val .= $this->decodeCharacterReference(true);
603-
$tok = $this->scanner->current();
604-
} else {
605-
if (strspn($tok, "\"'<=`") > 0) {
599+
while (false !== $tok) {
600+
switch ($tok) {
601+
case "\n":
602+
case "\f":
603+
case ' ':
604+
case "\t":
605+
case '>':
606+
break 2;
607+
608+
case '&':
609+
$val .= $this->decodeCharacterReference(true);
610+
$tok = $this->scanner->current();
611+
612+
break;
613+
614+
case "'":
615+
case '"':
616+
case '<':
617+
case '=':
618+
case '`':
606619
$this->parseError('Unexpected chars in unquoted attribute value %s', $tok);
607-
}
608-
$val .= $tok;
609-
$tok = $this->scanner->next();
620+
$val .= $tok;
621+
$tok = $this->scanner->next();
622+
break;
623+
624+
default:
625+
$val .= $this->scanner->charsUntil("\t\n\f >&\"'<=`");
626+
627+
$tok = $this->scanner->current();
610628
}
611629
}
612630

0 commit comments

Comments
 (0)