Skip to content

Commit 88b7c66

Browse files
authored
Merge pull request #155 from stof/optimize_attributes
Optimize the parsing of unquoted attributes
2 parents 3ed3bdc + 88431be commit 88b7c66

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
@@ -592,19 +592,37 @@ protected function quotedAttributeValue($quote)
592592

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

0 commit comments

Comments
 (0)