From: Tim Starling Date: Tue, 8 Jan 2008 05:12:20 +0000 (+0000) Subject: * Fixed handling of whitespace before HTML comments, slightly broken since r29292. X-Git-Tag: 1.31.0-rc.0~50108 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=6533120d2d0f5016a605cdfbd1033a53130d0255;p=lhc%2Fweb%2Fwiklou.git * Fixed handling of whitespace before HTML comments, slightly broken since r29292. * Fixed ot['pre'] bug --- diff --git a/includes/Parser.php b/includes/Parser.php index 6c0dc39984..ea02a6e619 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -2777,7 +2777,7 @@ class Parser $i = strlen( $text ); } else { // Search backwards for leading whitespace - $wsStart = $i ? ( $i - strspn( $revText, ' ', strlen( $text ) - $i - 1 ) ) : 0; + $wsStart = $i ? ( $i - strspn( $revText, ' ', strlen( $text ) - $i ) ) : 0; // Search forwards for trailing whitespace // $wsEnd will be the position of the last space $wsEnd = $endPos + 2 + strspn( $text, ' ', $endPos + 3 ); @@ -2787,11 +2787,18 @@ class Parser { $startPos = $wsStart; $endPos = $wsEnd + 1; + // 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 ) ) { + $accum = substr( $accum, 0, -$wsLength ); + } } else { // No line to eat, just take the comment itself $startPos = $i; $endPos += 2; } + $inner = substr( $text, $startPos, $endPos - $startPos + 1 ); $accum .= '' . htmlspecialchars( $inner ) . ''; $i = $endPos + 1; @@ -5425,7 +5432,7 @@ class PPFrame { } elseif ( $root->nodeName == 'comment' ) { # HTML-style comment if ( $this->parser->ot['html'] - || ( $this->parser->ot['pre'] && $this->mOptions->getRemoveComments() ) + || ( $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() ) || ( $flags & self::STRIP_COMMENTS ) ) { $s = '';