← All changes
|
vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php
+26
-23
3.0.16
→
3.2.90
View file →
| @@ -216,9 +216,9 @@ | ||
| 216 | 216 | * @return bool |
| 217 | 217 | */ |
| 218 | 218 | protected function rawText($tok) |
| 219 | 219 | { |
| 220 | - if (\is_null($this->untilTag)) { | |
| 220 | + if (is_null($this->untilTag)) { | |
| 221 | 221 | return $this->text($tok); |
| 222 | 222 | } |
| 223 | 223 | $sequence = '</' . $this->untilTag . '>'; |
| 224 | 224 | $txt = $this->readUntilSequence($sequence); |
| @@ -234,9 +234,9 @@ | ||
| 234 | 234 | * @return bool |
| 235 | 235 | */ |
| 236 | 236 | protected function rcdata($tok) |
| 237 | 237 | { |
| 238 | - if (\is_null($this->untilTag)) { | |
| 238 | + if (is_null($this->untilTag)) { | |
| 239 | 239 | return $this->text($tok); |
| 240 | 240 | } |
| 241 | 241 | $sequence = '</' . $this->untilTag; |
| 242 | 242 | $txt = ''; |
| @@ -249,9 +249,9 @@ | ||
| 249 | 249 | $txt .= $tok; |
| 250 | 250 | $tok = $this->scanner->next(); |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | - $len = \strlen($sequence); | |
| 253 | + $len = strlen($sequence); | |
| 254 | 254 | $this->scanner->consume($len); |
| 255 | 255 | $len += $this->scanner->whitespace(); |
| 256 | 256 | if ('>' !== $this->scanner->current()) { |
| 257 | 257 | $this->parseError('Unclosed RCDATA end tag'); |
| @@ -313,9 +313,9 @@ | ||
| 313 | 313 | } |
| 314 | 314 | return $this->bogusComment('</'); |
| 315 | 315 | } |
| 316 | 316 | $name = $this->scanner->charsUntil("\n\f \t>"); |
| 317 | - $name = self::CONFORMANT_XML === $this->mode ? $name : \strtolower($name); | |
| 317 | + $name = self::CONFORMANT_XML === $this->mode ? $name : strtolower($name); | |
| 318 | 318 | // Trash whitespace. |
| 319 | 319 | $this->scanner->whitespace(); |
| 320 | 320 | $tok = $this->scanner->current(); |
| 321 | 321 | if ('>' != $tok) { |
| @@ -333,9 +333,9 @@ | ||
| 333 | 333 | protected function tagName() |
| 334 | 334 | { |
| 335 | 335 | // We know this is at least one char. |
| 336 | 336 | $name = $this->scanner->charsWhile(':_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'); |
| 337 | - $name = self::CONFORMANT_XML === $this->mode ? $name : \strtolower($name); | |
| 337 | + $name = self::CONFORMANT_XML === $this->mode ? $name : strtolower($name); | |
| 338 | 338 | $attributes = array(); |
| 339 | 339 | $selfClose = \false; |
| 340 | 340 | // Handle attribute parse exceptions here so that we can |
| 341 | 341 | // react by trying to build a sensible parse tree. |
| @@ -347,9 +347,9 @@ | ||
| 347 | 347 | } catch (ParseError $e) { |
| 348 | 348 | $selfClose = \false; |
| 349 | 349 | } |
| 350 | 350 | $mode = $this->events->startTag($name, $attributes, $selfClose); |
| 351 | - if (\is_int($mode)) { | |
| 351 | + if (is_int($mode)) { | |
| 352 | 352 | $this->setTextMode($mode, $name); |
| 353 | 353 | } |
| 354 | 354 | $this->scanner->consume(); |
| 355 | 355 | return \true; |
| @@ -407,10 +407,10 @@ | ||
| 407 | 407 | $this->scanner->unconsume(); |
| 408 | 408 | // Let the caller figure out how to handle this. |
| 409 | 409 | throw new ParseError('Start tag inside of attribute.'); |
| 410 | 410 | } |
| 411 | - $name = \strtolower($this->scanner->charsUntil("/>=\n\f\t ")); | |
| 412 | - if (0 == \strlen($name)) { | |
| 411 | + $name = strtolower($this->scanner->charsUntil("/>=\n\f\t ")); | |
| 412 | + if (0 == strlen($name)) { | |
| 413 | 413 | $tok = $this->scanner->current(); |
| 414 | 414 | $this->parseError('Expected an attribute name, got %s.', $tok); |
| 415 | 415 | // Really, only '=' can be the char here. Everything else gets absorbed |
| 416 | 416 | // under one rule or another. |
| @@ -422,12 +422,12 @@ | ||
| 422 | 422 | // But method "DOMElement::setAttribute" is throwing exception |
| 423 | 423 | // because of it's own internal restriction so these have to be filtered. |
| 424 | 424 | // see issue #23: https://github.com/Masterminds/html5-php/issues/23 |
| 425 | 425 | // and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name |
| 426 | - if (\preg_match("/[\x01-,\\/;-@[-^`{-]/u", $name)) { | |
| 426 | + if (preg_match("/[\x01-,\\/;-@[-^`{-]/u", $name)) { | |
| 427 | 427 | $this->parseError('Unexpected characters in attribute name: %s', $name); |
| 428 | 428 | $isValidAttribute = \false; |
| 429 | - } elseif (\preg_match('/^[0-9.-]/u', $name)) { | |
| 429 | + } elseif (preg_match('/^[0-9.-]/u', $name)) { | |
| 430 | 430 | $this->parseError('Unexpected character at the begining of attribute name: %s', $name); |
| 431 | 431 | $isValidAttribute = \false; |
| 432 | 432 | } |
| 433 | 433 | // 8.1.2.3 |
| @@ -432,9 +432,9 @@ | ||
| 432 | 432 | } |
| 433 | 433 | // 8.1.2.3 |
| 434 | 434 | $this->scanner->whitespace(); |
| 435 | 435 | $val = $this->attributeValue(); |
| 436 | - if ($isValidAttribute) { | |
| 436 | + if ($isValidAttribute && !array_key_exists($name, $attributes)) { | |
| 437 | 437 | $attributes[$name] = $val; |
| 438 | 438 | } |
| 439 | 439 | return \true; |
| 440 | 440 | } |
| @@ -665,9 +665,9 @@ | ||
| 665 | 665 | } |
| 666 | 666 | $stop = " \n\f>"; |
| 667 | 667 | $doctypeName = $this->scanner->charsUntil($stop); |
| 668 | 668 | // Lowercase ASCII, replace \0 with FFFD |
| 669 | - $doctypeName = \strtolower(\strtr($doctypeName, "\x00", UTF8Utils::FFFD)); | |
| 669 | + $doctypeName = strtolower(strtr($doctypeName, "\x00", UTF8Utils::FFFD)); | |
| 670 | 670 | $tok = $this->scanner->current(); |
| 671 | 671 | // If false, emit a parse error, DOCTYPE, and return. |
| 672 | 672 | if (\false === $tok) { |
| 673 | 673 | $this->parseError('Unexpected EOF in DOCTYPE declaration.'); |
| @@ -676,9 +676,9 @@ | ||
| 676 | 676 | } |
| 677 | 677 | // Short DOCTYPE, like <!DOCTYPE html> |
| 678 | 678 | if ('>' == $tok) { |
| 679 | 679 | // DOCTYPE without a name. |
| 680 | - if (0 == \strlen($doctypeName)) { | |
| 680 | + if (0 == strlen($doctypeName)) { | |
| 681 | 681 | $this->parseError('Expected a DOCTYPE name. Got nothing.'); |
| 682 | 682 | $this->events->doctype($doctypeName, 0, null, \true); |
| 683 | 683 | $this->scanner->consume(); |
| 684 | 684 | return \true; |
| @@ -687,9 +687,9 @@ | ||
| 687 | 687 | $this->scanner->consume(); |
| 688 | 688 | return \true; |
| 689 | 689 | } |
| 690 | 690 | $this->scanner->whitespace(); |
| 691 | - $pub = \strtoupper($this->scanner->getAsciiAlpha()); | |
| 691 | + $pub = strtoupper($this->scanner->getAsciiAlpha()); | |
| 692 | 692 | $white = $this->scanner->whitespace(); |
| 693 | 693 | // Get ID, and flag it as pub or system. |
| 694 | 694 | if (('PUBLIC' == $pub || 'SYSTEM' == $pub) && $white > 0) { |
| 695 | 695 | // Get the sys ID. |
| @@ -802,9 +802,9 @@ | ||
| 802 | 802 | $tok = $this->scanner->next(); |
| 803 | 803 | $procName = $this->scanner->getAsciiAlpha(); |
| 804 | 804 | $white = $this->scanner->whitespace(); |
| 805 | 805 | // If not a PI, send to bogusComment. |
| 806 | - if (0 == \strlen($procName) || 0 == $white || \false == $this->scanner->current()) { | |
| 806 | + if (0 == strlen($procName) || 0 == $white || \false == $this->scanner->current()) { | |
| 807 | 807 | $this->parseError("Expected processing instruction name, got {$tok}"); |
| 808 | 808 | $this->bogusComment('<?' . $tok . $procName); |
| 809 | 809 | return \true; |
| 810 | 810 | } |
| @@ -838,9 +838,9 @@ | ||
| 838 | 838 | protected function readUntilSequence($sequence) |
| 839 | 839 | { |
| 840 | 840 | $buffer = ''; |
| 841 | 841 | // Optimization for reading larger blocks faster. |
| 842 | - $first = \substr($sequence, 0, 1); | |
| 842 | + $first = substr($sequence, 0, 1); | |
| 843 | 843 | while (\false !== $this->scanner->current()) { |
| 844 | 844 | $buffer .= $this->scanner->charsUntil($first); |
| 845 | 845 | // Stop as soon as we hit the stopping condition. |
| 846 | 846 | if ($this->scanner->sequenceMatches($sequence, \false)) { |
| @@ -872,9 +872,9 @@ | ||
| 872 | 872 | * @return bool |
| 873 | 873 | */ |
| 874 | 874 | protected function sequenceMatches($sequence, $caseSensitive = \true) |
| 875 | 875 | { |
| 876 | - @\trigger_error(__METHOD__ . ' method is deprecated since version 2.4 and will be removed in 3.0. Use Scanner::sequenceMatches() instead.', \E_USER_DEPRECATED); | |
| 876 | + @trigger_error(__METHOD__ . ' method is deprecated since version 2.4 and will be removed in 3.0. Use Scanner::sequenceMatches() instead.', \E_USER_DEPRECATED); | |
| 877 | 877 | return $this->scanner->sequenceMatches($sequence, $caseSensitive); |
| 878 | 878 | } |
| 879 | 879 | /** |
| 880 | 880 | * Send a TEXT event with the contents of the text buffer. |
| @@ -913,12 +913,12 @@ | ||
| 913 | 913 | * @return string |
| 914 | 914 | */ |
| 915 | 915 | protected function parseError($msg) |
| 916 | 916 | { |
| 917 | - $args = \func_get_args(); | |
| 918 | - if (\count($args) > 1) { | |
| 919 | - \array_shift($args); | |
| 920 | - $msg = \vsprintf($msg, $args); | |
| 917 | + $args = func_get_args(); | |
| 918 | + if (count($args) > 1) { | |
| 919 | + array_shift($args); | |
| 920 | + $msg = vsprintf($msg, $args); | |
| 921 | 921 | } |
| 922 | 922 | $line = $this->scanner->currentLine(); |
| 923 | 923 | $col = $this->scanner->columnOffset(); |
| 924 | 924 | $this->events->parseError($msg, $line, $col); |
| @@ -955,9 +955,9 @@ | ||
| 955 | 955 | $this->parseError('Expected &#DEC; &#HEX;, got EOF'); |
| 956 | 956 | $this->scanner->unconsume(1); |
| 957 | 957 | return '&'; |
| 958 | 958 | } |
| 959 | - // Hexidecimal encoding. | |
| 959 | + // Hexadecimal encoding. | |
| 960 | 960 | // X[0-9a-fA-F]+; |
| 961 | 961 | // x[0-9a-fA-F]+; |
| 962 | 962 | if ('x' === $tok || 'X' === $tok) { |
| 963 | 963 | $tok = $this->scanner->next(); |
| @@ -1023,8 +1023,11 @@ | ||
| 1023 | 1023 | * @return bool True if it is a letter, False otherwise |
| 1024 | 1024 | */ |
| 1025 | 1025 | protected function is_alpha($input) |
| 1026 | 1026 | { |
| 1027 | - $code = \ord($input); | |
| 1027 | + if (!is_string($input) || 1 !== strlen($input)) { | |
| 1028 | + return \false; | |
| 1029 | + } | |
| 1030 | + $code = ord($input); | |
| 1028 | 1031 | return $code >= 97 && $code <= 122 || $code >= 65 && $code <= 90; |
| 1029 | 1032 | } |
| 1030 | 1033 | } |