← All changes
|
vendor/masterminds/html5/src/HTML5/Parser/DOMTreeBuilder.php
+20
-24
3.0.13
→
3.2.89
View file →
| @@ -134,9 +134,9 @@ | ||
| 134 | 134 | } elseif (isset($this->options['implicitNamespaces'])) { |
| 135 | 135 | $implicitNS = $this->options['implicitNamespaces']; |
| 136 | 136 | } |
| 137 | 137 | // Fill $nsStack with the defalut HTML5 namespaces, plus the "implicitNamespaces" array taken form $options |
| 138 | - \array_unshift($this->nsStack, $implicitNS + array('' => self::NAMESPACE_HTML) + $this->implicitNamespaces); | |
| 138 | + array_unshift($this->nsStack, $implicitNS + array('' => self::NAMESPACE_HTML) + $this->implicitNamespaces); | |
| 139 | 139 | if ($isFragment) { |
| 140 | 140 | $this->insertMode = static::IM_IN_BODY; |
| 141 | 141 | $this->frag = $this->doc->createDocumentFragment(); |
| 142 | 142 | $this->current = $this->frag; |
| @@ -167,10 +167,8 @@ | ||
| 167 | 167 | * Provide an instruction processor. |
| 168 | 168 | * |
| 169 | 169 | * This is used for handling Processor Instructions as they are |
| 170 | 170 | * inserted. If omitted, PI's are inserted directly into the DOM tree. |
| 171 | - * | |
| 172 | - * @param InstructionProcessor $proc | |
| 173 | 171 | */ |
| 174 | 172 | public function setInstructionProcessor(InstructionProcessor $proc) |
| 175 | 173 | { |
| 176 | 174 | $this->processor = $proc; |
| @@ -254,9 +252,9 @@ | ||
| 254 | 252 | } |
| 255 | 253 | $pushes = 0; |
| 256 | 254 | // when we found a tag thats appears inside $nsRoots, we have to switch the defalut namespace |
| 257 | 255 | if (isset($this->nsRoots[$lname]) && $this->nsStack[0][''] !== $this->nsRoots[$lname]) { |
| 258 | - \array_unshift($this->nsStack, array('' => $this->nsRoots[$lname]) + $this->nsStack[0]); | |
| 256 | + array_unshift($this->nsStack, array('' => $this->nsRoots[$lname]) + $this->nsStack[0]); | |
| 259 | 257 | ++$pushes; |
| 260 | 258 | } |
| 261 | 259 | $needsWorkaround = \false; |
| 262 | 260 | if (isset($this->options['xmlNamespaces']) && $this->options['xmlNamespaces']) { |
| @@ -263,12 +261,12 @@ | ||
| 263 | 261 | // when xmlNamespaces is true a and we found a 'xmlns' or 'xmlns:*' attribute, we should add a new item to the $nsStack |
| 264 | 262 | foreach ($attributes as $aName => $aVal) { |
| 265 | 263 | if ('xmlns' === $aName) { |
| 266 | 264 | $needsWorkaround = $aVal; |
| 267 | - \array_unshift($this->nsStack, array('' => $aVal) + $this->nsStack[0]); | |
| 265 | + array_unshift($this->nsStack, array('' => $aVal) + $this->nsStack[0]); | |
| 268 | 266 | ++$pushes; |
| 269 | - } elseif ('xmlns' === (($pos = \strpos($aName, ':')) ? \substr($aName, 0, $pos) : '')) { | |
| 270 | - \array_unshift($this->nsStack, array(\substr($aName, $pos + 1) => $aVal) + $this->nsStack[0]); | |
| 267 | + } elseif ('xmlns' === (($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : '')) { | |
| 268 | + array_unshift($this->nsStack, array(substr($aName, $pos + 1) => $aVal) + $this->nsStack[0]); | |
| 271 | 269 | ++$pushes; |
| 272 | 270 | } |
| 273 | 271 | } |
| 274 | 272 | } |
| @@ -285,20 +283,18 @@ | ||
| 285 | 283 | } |
| 286 | 284 | } |
| 287 | 285 | } |
| 288 | 286 | try { |
| 289 | - $prefix = ($pos = \strpos($lname, ':')) ? \substr($lname, 0, $pos) : ''; | |
| 287 | + $prefix = ($pos = strpos($lname, ':')) ? substr($lname, 0, $pos) : ''; | |
| 290 | 288 | if (\false !== $needsWorkaround) { |
| 291 | - $xml = "<{$lname} xmlns=\"{$needsWorkaround}\" " . (\strlen($prefix) && isset($this->nsStack[0][$prefix]) ? "xmlns:{$prefix}=\"" . $this->nsStack[0][$prefix] . '"' : '') . '/>'; | |
| 289 | + $xml = "<{$lname} xmlns=\"{$needsWorkaround}\" " . (strlen($prefix) && isset($this->nsStack[0][$prefix]) ? "xmlns:{$prefix}=\"" . $this->nsStack[0][$prefix] . '"' : '') . '/>'; | |
| 292 | 290 | $frag = new \DOMDocument('1.0', 'UTF-8'); |
| 293 | 291 | $frag->loadXML($xml); |
| 294 | 292 | $ele = $this->doc->importNode($frag->documentElement, \true); |
| 293 | + } else if (!isset($this->nsStack[0][$prefix]) || '' === $prefix && isset($this->options[self::OPT_DISABLE_HTML_NS]) && $this->options[self::OPT_DISABLE_HTML_NS]) { | |
| 294 | + $ele = $this->doc->createElement($lname); | |
| 295 | 295 | } else { |
| 296 | - if (!isset($this->nsStack[0][$prefix]) || '' === $prefix && isset($this->options[self::OPT_DISABLE_HTML_NS]) && $this->options[self::OPT_DISABLE_HTML_NS]) { | |
| 297 | - $ele = $this->doc->createElement($lname); | |
| 298 | - } else { | |
| 299 | - $ele = $this->doc->createElementNS($this->nsStack[0][$prefix], $lname); | |
| 300 | - } | |
| 296 | + $ele = $this->doc->createElementNS($this->nsStack[0][$prefix], $lname); | |
| 301 | 297 | } |
| 302 | 298 | } catch (\DOMException $e) { |
| 303 | 299 | $this->parseError("Illegal tag name: <{$lname}>. Replaced with <invalid>."); |
| 304 | 300 | $ele = $this->doc->createElement('invalid'); |
| @@ -309,11 +305,11 @@ | ||
| 309 | 305 | // When we add some namespacess, we have to track them. Later, when "endElement" is invoked, we have to remove them. |
| 310 | 306 | // When we are on a void tag, we do not need to care about namesapce nesting. |
| 311 | 307 | if ($pushes > 0 && !Elements::isA($name, Elements::VOID_TAG)) { |
| 312 | 308 | // PHP tends to free the memory used by DOM, |
| 313 | - // to avoid spl_object_hash collisions whe have to avoid garbage collection of $ele storing it into $pushes | |
| 309 | + // to avoid spl_object_id collisions we have to avoid garbage collection of $ele storing it into $pushes | |
| 314 | 310 | // see https://bugs.php.net/bug.php?id=67459 |
| 315 | - $this->pushes[\spl_object_hash($ele)] = array($pushes, $ele); | |
| 311 | + $this->pushes[spl_object_id($ele)] = array($pushes, $ele); | |
| 316 | 312 | } |
| 317 | 313 | foreach ($attributes as $aName => $aVal) { |
| 318 | 314 | // xmlns attributes can't be set |
| 319 | 315 | if ('xmlns' === $aName) { |
| @@ -325,9 +321,9 @@ | ||
| 325 | 321 | $aName = Elements::normalizeMathMlAttribute($aName); |
| 326 | 322 | } |
| 327 | 323 | $aVal = (string) $aVal; |
| 328 | 324 | try { |
| 329 | - $prefix = ($pos = \strpos($aName, ':')) ? \substr($aName, 0, $pos) : \false; | |
| 325 | + $prefix = ($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : \false; | |
| 330 | 326 | if ('xmlns' === $prefix) { |
| 331 | 327 | $ele->setAttributeNS(self::NAMESPACE_XMLNS, $aName, $aVal); |
| 332 | 328 | } elseif (\false !== $prefix && isset($this->nsStack[0][$prefix])) { |
| 333 | 329 | $ele->setAttributeNS($this->nsStack[0][$prefix], $aName, $aVal); |
| @@ -368,9 +364,9 @@ | ||
| 368 | 364 | // but we have to remove the namespaces pushed to $nsStack. |
| 369 | 365 | if ($pushes > 0 && Elements::isA($name, Elements::VOID_TAG)) { |
| 370 | 366 | // remove the namespaced definded by current node |
| 371 | 367 | for ($i = 0; $i < $pushes; ++$i) { |
| 372 | - \array_shift($this->nsStack); | |
| 368 | + array_shift($this->nsStack); | |
| 373 | 369 | } |
| 374 | 370 | } |
| 375 | 371 | if ($selfClosing) { |
| 376 | 372 | $this->endTag($name); |
| @@ -390,9 +386,9 @@ | ||
| 390 | 386 | return; |
| 391 | 387 | } |
| 392 | 388 | if ($this->insertMode <= static::IM_BEFORE_HTML) { |
| 393 | 389 | // 8.2.5.4.2 |
| 394 | - if (\in_array($name, array('html', 'br', 'head', 'title'))) { | |
| 390 | + if (in_array($name, array('html', 'br', 'head', 'title'))) { | |
| 395 | 391 | $this->startTag('html'); |
| 396 | 392 | $this->endTag($name); |
| 397 | 393 | $this->insertMode = static::IM_BEFORE_HEAD; |
| 398 | 394 | return; |
| @@ -404,9 +400,9 @@ | ||
| 404 | 400 | // Special case handling for SVG. |
| 405 | 401 | if ($this->insertMode === static::IM_IN_SVG) { |
| 406 | 402 | $lname = Elements::normalizeSvgElement($lname); |
| 407 | 403 | } |
| 408 | - $cid = \spl_object_hash($this->current); | |
| 404 | + $cid = spl_object_id($this->current); | |
| 409 | 405 | // XXX: HTML has no parent. What do we do, though, |
| 410 | 406 | // if this element appears in the wrong place? |
| 411 | 407 | if ('html' === $lname) { |
| 412 | 408 | return; |
| @@ -413,9 +409,9 @@ | ||
| 413 | 409 | } |
| 414 | 410 | // remove the namespaced definded by current node |
| 415 | 411 | if (isset($this->pushes[$cid])) { |
| 416 | 412 | for ($i = 0; $i < $this->pushes[$cid][0]; ++$i) { |
| 417 | - \array_shift($this->nsStack); | |
| 413 | + array_shift($this->nsStack); | |
| 418 | 414 | } |
| 419 | 415 | unset($this->pushes[$cid]); |
| 420 | 416 | } |
| 421 | 417 | if (!$this->autoclose($lname)) { |
| @@ -447,9 +443,9 @@ | ||
| 447 | 443 | // Per '8.2.5.4.3 The "before head" insertion mode' the characters |
| 448 | 444 | // " \t\n\r\f" should be ignored but no mention of a parse error. This is |
| 449 | 445 | // practical as most documents contain these characters. Other text is not |
| 450 | 446 | // expected here so recording a parse error is necessary. |
| 451 | - $dataTmp = \trim($data, " \t\n\r\f"); | |
| 447 | + $dataTmp = trim($data, " \t\n\r\f"); | |
| 452 | 448 | if (!empty($dataTmp)) { |
| 453 | 449 | // fprintf(STDOUT, "Unexpected insert mode: %d", $this->insertMode); |
| 454 | 450 | $this->parseError('Unexpected text. Ignoring: ' . $dataTmp); |
| 455 | 451 | } |
| @@ -464,9 +460,9 @@ | ||
| 464 | 460 | // If the $current isn't the $root, do we need to do anything? |
| 465 | 461 | } |
| 466 | 462 | public function parseError($msg, $line = 0, $col = 0) |
| 467 | 463 | { |
| 468 | - $this->errors[] = \sprintf('Line %d, Col %d: %s', $line, $col, $msg); | |
| 464 | + $this->errors[] = sprintf('Line %d, Col %d: %s', $line, $col, $msg); | |
| 469 | 465 | } |
| 470 | 466 | public function getErrors() |
| 471 | 467 | { |
| 472 | 468 | return $this->errors; |
| @@ -478,9 +474,9 @@ | ||
| 478 | 474 | } |
| 479 | 475 | public function processingInstruction($name, $data = null) |
| 480 | 476 | { |
| 481 | 477 | // XXX: Ignore initial XML declaration, per the spec. |
| 482 | - if ($this->insertMode === static::IM_INITIAL && 'xml' === \strtolower($name)) { | |
| 478 | + if ($this->insertMode === static::IM_INITIAL && 'xml' === strtolower($name)) { | |
| 483 | 479 | return; |
| 484 | 480 | } |
| 485 | 481 | // Important: The processor may modify the current DOM tree however it sees fit. |
| 486 | 482 | if ($this->processor instanceof InstructionProcessor) { |