r29415 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29414‎ | r29415 | r29416 >
Date:05:12, 8 January 2008
Author:tstarling
Status:old
Tags:
Comment:
* Fixed handling of whitespace before HTML comments, slightly broken since r29292.
* Fixed ot['pre'] bug
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -2777,7 +2777,7 @@
27782778 $i = strlen( $text );
27792779 } else {
27802780 // Search backwards for leading whitespace
2781 - $wsStart = $i ? ( $i - strspn( $revText, ' ', strlen( $text ) - $i - 1 ) ) : 0;
 2781+ $wsStart = $i ? ( $i - strspn( $revText, ' ', strlen( $text ) - $i ) ) : 0;
27822782 // Search forwards for trailing whitespace
27832783 // $wsEnd will be the position of the last space
27842784 $wsEnd = $endPos + 2 + strspn( $text, ' ', $endPos + 3 );
@@ -2787,11 +2787,18 @@
27882788 {
27892789 $startPos = $wsStart;
27902790 $endPos = $wsEnd + 1;
 2791+ // Remove leading whitespace from the end of the accumulator
 2792+ // Sanity check first though
 2793+ $wsLength = $i - $wsStart;
 2794+ if ( $wsLength > 0 && substr( $accum, -$wsLength ) === str_repeat( ' ', $wsLength ) ) {
 2795+ $accum = substr( $accum, 0, -$wsLength );
 2796+ }
27912797 } else {
27922798 // No line to eat, just take the comment itself
27932799 $startPos = $i;
27942800 $endPos += 2;
27952801 }
 2802+
27962803 $inner = substr( $text, $startPos, $endPos - $startPos + 1 );
27972804 $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
27982805 $i = $endPos + 1;
@@ -5425,7 +5432,7 @@
54265433 } elseif ( $root->nodeName == 'comment' ) {
54275434 # HTML-style comment
54285435 if ( $this->parser->ot['html']
5429 - || ( $this->parser->ot['pre'] && $this->mOptions->getRemoveComments() )
 5436+ || ( $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() )
54305437 || ( $flags & self::STRIP_COMMENTS ) )
54315438 {
54325439 $s = '';

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r29292* Merged comment handling with the main loop of preprocessToDom(). This fixes...tstarling12:39, 5 January 2008

Status & tagging log