From: Arlo Breault Date: Wed, 20 Mar 2019 21:02:39 +0000 (-0400) Subject: BlockLevelPass: further fixes for T218817 X-Git-Tag: 1.34.0-rc.0~2453^2 X-Git-Url: http://git.cyclocoop.org//%27http:/code.google.com/p/ie7-js//%27?a=commitdiff_plain;h=73239ee9bdb2598ada26c20a1b0009c501b162bc;p=lhc%2Fweb%2Fwiklou.git BlockLevelPass: further fixes for T218817 The previous fix for T218817 (I22eebb70af1b19d7c25241fc78bfcced4470e78a) was a bit premature: we didn't notice that ExplodeIterator *also* used a different Iterator::key() than ArrayIterator -- it used the string position as a key, not the line number. Combined with an inequality test for "not the last line" meant that almost every line was now the "last line" and we were missing a lot of needed newlines. Count the lines ourselves to fix the problem. Bug: T208070 Bug: T218817 Change-Id: I55a2c4c0ec304292162c51aa88b206fea0142392 --- diff --git a/includes/parser/BlockLevelPass.php b/includes/parser/BlockLevelPass.php index 6611e20c0a..6d6af7716c 100644 --- a/includes/parser/BlockLevelPass.php +++ b/includes/parser/BlockLevelPass.php @@ -192,6 +192,7 @@ class BlockLevelPass { # happening here is handling of block-level elements p, pre, # and making lists from lines starting with * # : etc. $textLines = StringUtils::explode( "\n", $text ); + # Count this way because $textLines could be an ExplodeIterator $lineCount = substr_count( $text, "\n" ) + 1; $lastPrefix = $output = ''; @@ -200,7 +201,9 @@ class BlockLevelPass { $pendingPTag = false; $inBlockquote = false; - foreach ( $textLines as $i => $inputLine ) { + $nextLineNum = 0; + foreach ( $textLines as $inputLine ) { + $nextLineNum += 1; # Fix up $lineStart if ( !$this->lineStart ) { $output .= $inputLine; @@ -407,7 +410,7 @@ class BlockLevelPass { $output .= $t; // Add a newline if there's an open paragraph // or we've yet to reach the last line. - if ( $i < $lineCount - 1 || $this->hasOpenParagraph() ) { + if ( $nextLineNum < $lineCount || $this->hasOpenParagraph() ) { $output .= "\n"; } } else {