X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fparser%2FPreprocessor_DOM.php;h=a28c0aa439d303162bb2c9be23044cd7b6b17aa7;hb=cdc53ad15b8131e1b4254cc788efa318a35fd804;hp=79a66e05e87893e4dd1a3e859afa03a470c7aef9;hpb=601519ee36462faabacf4547c9aefaf7e8726476;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php index 79a66e05e8..a28c0aa439 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/Preprocessor_DOM.php @@ -196,6 +196,7 @@ class Preprocessor_DOM extends Preprocessor { $forInclusion = $flags & Parser::PTD_FOR_INCLUSION; $xmlishElements = $this->parser->getStripList(); + $xmlishAllowMissingEndTag = [ 'includeonly', 'noinclude', 'onlyinclude' ]; $enableOnlyinclude = false; if ( $forInclusion ) { $ignoredTags = [ 'includeonly', '/includeonly' ]; @@ -237,6 +238,8 @@ class Preprocessor_DOM extends Preprocessor { $inHeading = false; // True if there are no more greater-than (>) signs right of $i $noMoreGT = false; + // Map of tag name => true if there are no more closing tags of given type right of $i + $noMoreClosingTag = []; // True to ignore all input up to the next $findOnlyinclude = $enableOnlyinclude; // Do a line-start run without outputting an LF character @@ -457,17 +460,29 @@ class Preprocessor_DOM extends Preprocessor { } else { $attrEnd = $tagEndPos; // Find closing tag - if ( preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i", + if ( + !isset( $noMoreClosingTag[$name] ) && + preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i", $text, $matches, PREG_OFFSET_CAPTURE, $tagEndPos + 1 ) ) { $inner = substr( $text, $tagEndPos + 1, $matches[0][1] - $tagEndPos - 1 ); $i = $matches[0][1] + strlen( $matches[0][0] ); $close = '' . htmlspecialchars( $matches[0][0] ) . ''; } else { - // No end tag -- let it run out to the end of the text. - $inner = substr( $text, $tagEndPos + 1 ); - $i = $lengthText; - $close = ''; + // No end tag + if ( in_array( $name, $xmlishAllowMissingEndTag ) ) { + // Let it run out to the end of the text. + $inner = substr( $text, $tagEndPos + 1 ); + $i = $lengthText; + $close = ''; + } else { + // Don't match the tag, treat opening tag as literal and resume parsing. + $i = $tagEndPos + 1; + $accum .= htmlspecialchars( substr( $text, $tagStartPos, $tagEndPos + 1 - $tagStartPos ) ); + // Cache results, otherwise we have O(N^2) performance for input like ... + $noMoreClosingTag[$name] = true; + continue; + } } } // and just become tags @@ -1462,6 +1477,10 @@ class PPFrame_DOM implements PPFrame { return true; } + /** + * @param int|string $name + * @return bool Always false in this implementation. + */ public function getArgument( $name ) { return false; } @@ -1646,6 +1665,10 @@ class PPTemplateFrame_DOM extends PPFrame_DOM { return $arguments; } + /** + * @param int $index + * @return string|bool + */ public function getNumberedArgument( $index ) { if ( !isset( $this->numberedArgs[$index] ) ) { return false; @@ -1660,6 +1683,10 @@ class PPTemplateFrame_DOM extends PPFrame_DOM { return $this->numberedExpansionCache[$index]; } + /** + * @param string $name + * @return string|bool + */ public function getNamedArgument( $name ) { if ( !isset( $this->namedArgs[$name] ) ) { return false; @@ -1672,6 +1699,10 @@ class PPTemplateFrame_DOM extends PPFrame_DOM { return $this->namedExpansionCache[$name]; } + /** + * @param int|string $name + * @return string|bool + */ public function getArgument( $name ) { $text = $this->getNumberedArgument( $name ); if ( $text === false ) { @@ -1738,6 +1769,10 @@ class PPCustomFrame_DOM extends PPFrame_DOM { return !count( $this->args ); } + /** + * @param int|string $index + * @return string|bool + */ public function getArgument( $index ) { if ( !isset( $this->args[$index] ) ) { return false;