From 543f46e9c08e0ff8c5e8b4e917fcc045730ef1bc Mon Sep 17 00:00:00 2001
From: Legoktm
Date: Thu, 4 Feb 2016 00:38:35 +0000
Subject: [PATCH] Revert "Preprocessor: Don't allow unclosed extension tags
(matching until end of input)"
This reverts commit f51d0d9a819f8f1c181350ced2f015ce97985fcc.
Breaks templates with non-closed tags, which
were previously acceptable.
Bug: T125754
Change-Id: I8bafb15eefac4e1d3e727c1c84782636d8b82c2b
---
includes/parser/Preprocessor_DOM.php | 16 +++++-----------
includes/parser/Preprocessor_Hash.php | 16 +++++-----------
tests/parser/parserTests.txt | 10 ++--------
.../phpunit/includes/parser/PreprocessorTest.php | 2 +-
4 files changed, 13 insertions(+), 31 deletions(-)
diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php
index 817f1538e3..4ca3a878bd 100644
--- a/includes/parser/Preprocessor_DOM.php
+++ b/includes/parser/Preprocessor_DOM.php
@@ -237,8 +237,6 @@ 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 = array();
// True to ignore all input up to the next
$findOnlyinclude = $enableOnlyinclude;
// Do a line-start run without outputting an LF character
@@ -459,21 +457,17 @@ class Preprocessor_DOM extends Preprocessor {
} else {
$attrEnd = $tagEndPos;
// Find closing tag
- if (
- !isset( $noMoreClosingTag[$name] ) &&
- preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i",
+ if ( 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 -- 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;
+ // No end tag -- let it run out to the end of the text.
+ $inner = substr( $text, $tagEndPos + 1 );
+ $i = $lengthText;
+ $close = '';
}
}
// and just become tags
diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php
index 28c49fdd5e..50eaefbce3 100644
--- a/includes/parser/Preprocessor_Hash.php
+++ b/includes/parser/Preprocessor_Hash.php
@@ -160,8 +160,6 @@ class Preprocessor_Hash 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 = array();
// True to ignore all input up to the next
$findOnlyinclude = $enableOnlyinclude;
// Do a line-start run without outputting an LF character
@@ -382,21 +380,17 @@ class Preprocessor_Hash extends Preprocessor {
} else {
$attrEnd = $tagEndPos;
// Find closing tag
- if (
- !isset( $noMoreClosingTag[$name] ) &&
- preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i",
+ if ( 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 = $matches[0][0];
} else {
- // No end tag -- don't match the tag, treat opening tag as literal and resume parsing.
- $i = $tagEndPos + 1;
- $accum->addLiteral( substr( $text, $tagStartPos, $tagEndPos + 1 - $tagStartPos ) );
- // Cache results, otherwise we have O(N^2) performance for input like ...
- $noMoreClosingTag[$name] = true;
- continue;
+ // No end tag -- let it run out to the end of the text.
+ $inner = substr( $text, $tagEndPos + 1 );
+ $i = $lengthText;
+ $close = null;
}
}
// and just become tags
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index 438fe314ca..cd2b769a53 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -2520,6 +2520,7 @@ Barack Obama of the United States
!! end
+## PHP parser discards the "
!! html/php
x
-
+
-!! html/php+tidy
-
-x
-
-<pre
!! html/parsoid
x
@@ -10880,8 +10876,6 @@ Un-closed
!! wikitext
!! html
-<includeonly>
-
!! end
## We used to, but no longer wt2wt this test since the default serializer
diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php
index b9402305bd..1ebba1a5e2 100644
--- a/tests/phpunit/includes/parser/PreprocessorTest.php
+++ b/tests/phpunit/includes/parser/PreprocessorTest.php
@@ -48,7 +48,7 @@ class PreprocessorTest extends MediaWikiTestCase {
array( " Foo bar ", "<noinclude> Foo bar </noinclude>" ),
array( "\n{{Foo}}\n", "<noinclude>\nFoo\n</noinclude>" ),
array( "\n{{Foo}}\n\n", "<noinclude>\nFoo\n</noinclude>\n" ),
- array( "foo bar", "<gallery>foo bar" ),
+ array( "foo bar", "galleryfoo bar" ),
array( "<{{foo}}>", "<foo>" ),
array( "<{{{foo}}}>", "<foo>" ),
array( "", "gallery</gallery</gallery>" ),
--
2.20.1