From: C. Scott Ananian Date: Thu, 8 Aug 2013 23:48:16 +0000 (-0400) Subject: Allow lines empty but for tabs and comments to be ignored. X-Git-Tag: 1.31.0-rc.0~18976^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=35422cadf2ad6ca46d629c9d3f0df452c51c6d97;p=lhc%2Fweb%2Fwiklou.git Allow lines empty but for tabs and comments to be ignored. We originally allowed only spaces around comments. Now allow tabs as well. This ought to affect very few pages, but it helps predictability and to maintain consistency between the PHP preprocessor and parsoid. Change-Id: Icb3ff6eec08aaa83ae332d03c910c13995c9c9ee --- diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php index c9e16b3559..48318b36f2 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/Preprocessor_DOM.php @@ -376,11 +376,11 @@ class Preprocessor_DOM implements Preprocessor { $i = $lengthText; } else { // Search backwards for leading whitespace - $wsStart = $i ? ( $i - strspn( $revText, ' ', $lengthText - $i ) ) : 0; + $wsStart = $i ? ( $i - strspn( $revText, " \t", $lengthText - $i ) ) : 0; // Search forwards for trailing whitespace // $wsEnd will be the position of the last space (or the '>' if there's none) - $wsEnd = $endPos + 2 + strspn( $text, ' ', $endPos + 3 ); + $wsEnd = $endPos + 2 + strspn( $text, " \t", $endPos + 3 ); // Keep looking forward as long as we're finding more // comments. @@ -390,7 +390,7 @@ class Preprocessor_DOM implements Preprocessor { if ( $c === false ) { break; } - $c = $c + 2 + strspn( $text, ' ', $c + 3 ); + $c = $c + 2 + strspn( $text, " \t", $c + 3 ); $comments[] = array( $wsEnd + 1, $c ); $wsEnd = $c; } @@ -405,7 +405,9 @@ class Preprocessor_DOM implements Preprocessor { // Remove leading whitespace from the end of the accumulator // Sanity check first though $wsLength = $i - $wsStart; - if ( $wsLength > 0 && substr( $accum, -$wsLength ) === str_repeat( ' ', $wsLength ) ) { + if ( $wsLength > 0 + && strspn( $accum, " \t", -$wsLength ) === $wsLength ) + { $accum = substr( $accum, 0, -$wsLength ); } diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index 333b70d786..3f5ca8efc5 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -302,11 +302,11 @@ class Preprocessor_Hash implements Preprocessor { $i = $lengthText; } else { // Search backwards for leading whitespace - $wsStart = $i ? ( $i - strspn( $revText, ' ', $lengthText - $i ) ) : 0; + $wsStart = $i ? ( $i - strspn( $revText, " \t", $lengthText - $i ) ) : 0; // Search forwards for trailing whitespace // $wsEnd will be the position of the last space (or the '>' if there's none) - $wsEnd = $endPos + 2 + strspn( $text, ' ', $endPos + 3 ); + $wsEnd = $endPos + 2 + strspn( $text, " \t", $endPos + 3 ); // Keep looking forward as long as we're finding more // comments. @@ -316,7 +316,7 @@ class Preprocessor_Hash implements Preprocessor { if ( $c === false ) { break; } - $c = $c + 2 + strspn( $text, ' ', $c + 3 ); + $c = $c + 2 + strspn( $text, " \t", $c + 3 ); $comments[] = array( $wsEnd + 1, $c ); $wsEnd = $c; } @@ -333,7 +333,7 @@ class Preprocessor_Hash implements Preprocessor { $wsLength = $i - $wsStart; if ( $wsLength > 0 && $accum->lastNode instanceof PPNode_Hash_Text - && substr( $accum->lastNode->value, -$wsLength ) === str_repeat( ' ', $wsLength ) ) + && strspn( $accum->lastNode->value, " \t", -$wsLength ) === $wsLength ) { $accum->lastNode->value = substr( $accum->lastNode->value, 0, -$wsLength ); } diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 128e25d155..c648ff0ee9 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -5432,7 +5432,7 @@ Multiple list tags generated by templates !!end !!test -Single-comment whitespace lines dont break lists, and so do multi-comment whitespace lines +Single-comment whitespace lines dont break lists, and neither do multi-comment whitespace lines !!input *a @@ -5450,6 +5450,26 @@ Single-comment whitespace lines dont break lists, and so do multi-comment whites !!end +!!test +Replacing whitespace with tabs still doesn't break the list (gerrit 78327) +!!input +*a + +*b + +*c + +*d +!!result + + +!!end + !!test Test the li-hack (Cannot test this with PHP parser since it relies on Tidy for the hack) diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php index fb13118091..7e9c9d46bd 100644 --- a/tests/phpunit/includes/parser/PreprocessorTest.php +++ b/tests/phpunit/includes/parser/PreprocessorTest.php @@ -209,11 +209,11 @@ class PreprocessorTest extends MediaWikiTestCase { array( "== h == ", "== h == <!--c1--> <!--c2--><!--c3--> " ), array( "== h == ", "== h == <!--c1--><!--c2--> <!--c3--> " ), array( "== h == ", "== h == <!--c1--> <!--c2--> <!--c3--> " ), + array( "== h == ", "== h ==<!--c1--> <!--c2-->" ), + array( "== h == ", "== h == <!--c1--> <!--c2-->" ), + array( "== h == ", "== h ==<!--c1--> <!--c2--> " ), /* These are not working: */ - array( "== h == ", "== h ==<!--c1--> <!--c2-->" ), - array( "== h == ", "== h == <!--c1--> <!--c2-->" ), - array( "== h == ", "== h ==<!--c1--> <!--c2--> " ), array( "== h == x ", "== h == x <!--c1--><!--c2--><!--c3--> " ), array( "== h == x ", "== h ==<!--c1--> x <!--c2--><!--c3--> " ), array( "== h == x ", "== h ==<!--c1--><!--c2--><!--c3--> x " ),