Fix small corner case in HTML comment removal
authorWil Mahan <wmahan@users.mediawiki.org>
Mon, 20 Sep 2004 16:05:37 +0000 (16:05 +0000)
committerWil Mahan <wmahan@users.mediawiki.org>
Mon, 20 Sep 2004 16:05:37 +0000 (16:05 +0000)
includes/Parser.php

index ba915f8..237704b 100644 (file)
@@ -1858,11 +1858,15 @@ class Parser
                return $text;
        }
 
-       # Remove '<!--', '-->', and everything between.
-       # To avoid leaving blank lines, when a comment is both preceded
-       # and followed by a newline (ignoring spaces), trim leading and
-       # trailing spaces and one of the newlines.
-       /* private */ function removeHTMLcomments( $text ) {
+       /**
+        * Remove '<!--', '-->', and everything between.
+        * To avoid leaving blank lines, when a comment is both preceded
+        * and followed by a newline (ignoring spaces), trim leading and
+        * trailing spaces and one of the newlines.
+        * 
+        * @access private
+        */
+       function removeHTMLcomments( $text ) {
                $fname='Parser::removeHTMLcomments';
                wfProfileIn( $fname );
                while (($start = strpos($text, '<!--')) !== false) {
@@ -1876,9 +1880,9 @@ class Parser
 
                        # Trim space and newline if the comment is both
                        # preceded and followed by a newline
-                       $spaceStart = $start - 1;
+                       $spaceStart = max($start - 1, 0);
                        $spaceLen = $end - $spaceStart;
-                       while (substr($text, $spaceStart, 1) === ' ') {
+                       while (substr($text, $spaceStart, 1) === ' ' && $spaceStart > 0) {
                                $spaceStart--;
                                $spaceLen++;
                        }