r5328 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5327‎ | r5328 | r5329 >
Date:16:05, 20 September 2004
Author:wmahan
Status:old
Tags:
Comment:
Fix small corner case in HTML comment removal
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -1858,11 +1858,15 @@
18591859 return $text;
18601860 }
18611861
1862 - # Remove '<!--', '-->', and everything between.
1863 - # To avoid leaving blank lines, when a comment is both preceded
1864 - # and followed by a newline (ignoring spaces), trim leading and
1865 - # trailing spaces and one of the newlines.
1866 - /* private */ function removeHTMLcomments( $text ) {
 1862+ /**
 1863+ * Remove '<!--', '-->', and everything between.
 1864+ * To avoid leaving blank lines, when a comment is both preceded
 1865+ * and followed by a newline (ignoring spaces), trim leading and
 1866+ * trailing spaces and one of the newlines.
 1867+ *
 1868+ * @access private
 1869+ */
 1870+ function removeHTMLcomments( $text ) {
18671871 $fname='Parser::removeHTMLcomments';
18681872 wfProfileIn( $fname );
18691873 while (($start = strpos($text, '<!--')) !== false) {
@@ -1876,9 +1880,9 @@
18771881
18781882 # Trim space and newline if the comment is both
18791883 # preceded and followed by a newline
1880 - $spaceStart = $start - 1;
 1884+ $spaceStart = max($start - 1, 0);
18811885 $spaceLen = $end - $spaceStart;
1882 - while (substr($text, $spaceStart, 1) === ' ') {
 1886+ while (substr($text, $spaceStart, 1) === ' ' && $spaceStart > 0) {
18831887 $spaceStart--;
18841888 $spaceLen++;
18851889 }

Status & tagging log