Fixing line-break issues with r85922
authorLeo Koppelkamm <diebuche@users.mediawiki.org>
Thu, 14 Apr 2011 10:02:51 +0000 (10:02 +0000)
committerLeo Koppelkamm <diebuche@users.mediawiki.org>
Thu, 14 Apr 2011 10:02:51 +0000 (10:02 +0000)
includes/parser/Parser.php
tests/parser/parserTests.txt

index a3043eb..f3ba2b5 100644 (file)
@@ -829,8 +829,13 @@ class Parser {
                foreach ( $lines as $outLine ) {
                        $line = trim( $outLine );
 
-                       if ( $line === '' ) { // empty line, go to next line
-                               $out .= $outLine . "\n";
+                       # empty line, go to next line,
+                       # but only append \n if outside of table
+                       if ( $line === '' ) { 
+                               $out .= $outLine;
+                               if ( !isset( $tables[0] ) ) {
+                                       $out .= "\n";
+                               }
                                continue;
                        }
                        $firstChars = $line[0];
@@ -877,8 +882,14 @@ class Parser {
                                if ( empty( $lastRow ) ) {
                                        $lastRow = NULL;
                                }
+                               $o = '';
                                $curtable = array_pop( $tables );
-                               $o = $this->generateTableHTML( $curtable ) . $line;
+                               
+                               #Add a line-ending before the table, but only if there isn't one already
+                               if ( substr( $out, -1 ) !== "\n" ) {
+                                       $o .= "\n";
+                               }
+                               $o .= $this->generateTableHTML( $curtable ) . $line . "\n";
 
                                if ( count( $tables ) > 0 ) {
                                        $table =& $this->last( $tables );
@@ -968,7 +979,12 @@ class Parser {
                if ( isset( $tables ) && count( $tables ) > 0 ) {
                        for ( $i = 0; $i < count( $tables ); $i++ ) {
                                $curtable = array_pop( $tables );
-                               $out .= $this->generateTableHTML( $curtable );
+                               $curtable = $this->generateTableHTML( $curtable );
+                               #Add a line-ending before the table, but only if there isn't one already
+                               if ( substr( $out, -1 ) !== "\n"  && $curtable !== "" ) {
+                                       $out .= "\n";
+                               }
+                               $out .= $curtable;
                        }
                }
 
@@ -1018,7 +1034,7 @@ class Parser {
         * @private
         */
        function generateTableHTML ( &$table ) {
-               $return = "\n";
+               $return = "";
                $return .= str_repeat( '<dl><dd>' , $table['indent'] );
                $return .= '<table';
                $return .= isset( $table['attributes'] ) ? $table['attributes'] : '';
index 9823ef0..3853f85 100644 (file)
@@ -1563,6 +1563,46 @@ Indented Tables, bug 20078
 </table></dd></dl>
 
 !! end
+
+!! test
+Arbitrary whitespace should not be prepended
+!! input
+{| 
+| 1 || 2
+
+|- 
+
+
+| 3 || 4
+|-
+
+| 6 || 8
+|}
+!! result
+<table>
+<tr>
+<td>1
+</td>
+<td>2
+</td>
+</tr>
+<tr>
+<td>3
+</td>
+<td>4
+</td>
+</tr>
+<tr>
+<td>6
+</td>
+<td>8
+</td>
+</tr>
+</table>
+
+!! end
+
+
 ###
 ### Internal links
 ###
@@ -5693,7 +5733,6 @@ http://===r:::https://b
 !!result
 <p><a rel="nofollow" class="external free" href="http://===r:::https://b">http://===r:::https://b</a>
 </p>
-
 !! end
 
 # Known to produce bad XML for now
@@ -5731,8 +5770,7 @@ MOVE YOUR MOUSE CURSOR OVER THIS TEXT
 <p>{{{|
 </p><p><u class="&#124;">}}}} &gt;
 </p><p><br style="onmouseover=&#39;alert(document.cookie);&#39;" />
-</p><p><br />
-MOVE YOUR MOUSE CURSOR OVER THIS TEXT
+</p><p>MOVE YOUR MOUSE CURSOR OVER THIS TEXT
 </p>
 <table>
 <tr>
@@ -7918,7 +7956,8 @@ y
 </td>
 <td>4
 </td>
-</tr></table>
+</tr>
+</table>
 <p>y
 </p>
 !! end