r86039 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86038‎ | r86039 | r86040 >
Date:10:02, 14 April 2011
Author:diebuche
Status:ok
Tags:
Comment:
Fixing line-break issues with r85922
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/parser/parserTests.txt
@@ -1563,6 +1563,46 @@
15641564 </table></dd></dl>
15651565
15661566 !! end
 1567+
 1568+!! test
 1569+Arbitrary whitespace should not be prepended
 1570+!! input
 1571+{|
 1572+| 1 || 2
 1573+
 1574+|-
 1575+
 1576+
 1577+| 3 || 4
 1578+|-
 1579+
 1580+| 6 || 8
 1581+|}
 1582+!! result
 1583+<table>
 1584+<tr>
 1585+<td>1
 1586+</td>
 1587+<td>2
 1588+</td>
 1589+</tr>
 1590+<tr>
 1591+<td>3
 1592+</td>
 1593+<td>4
 1594+</td>
 1595+</tr>
 1596+<tr>
 1597+<td>6
 1598+</td>
 1599+<td>8
 1600+</td>
 1601+</tr>
 1602+</table>
 1603+
 1604+!! end
 1605+
 1606+
15671607 ###
15681608 ### Internal links
15691609 ###
@@ -5693,7 +5733,6 @@
56945734 !!result
56955735 <p><a rel="nofollow" class="external free" href="http://===r:::https://b">http://===r:::https://b</a>
56965736 </p>
5697 -
56985737 !! end
56995738
57005739 # Known to produce bad XML for now
@@ -5731,8 +5770,7 @@
57325771 <p>{{{|
57335772 </p><p><u class="&#124;">}}}} &gt;
57345773 </p><p><br style="onmouseover=&#39;alert(document.cookie);&#39;" />
5735 -</p><p><br />
5736 -MOVE YOUR MOUSE CURSOR OVER THIS TEXT
 5774+</p><p>MOVE YOUR MOUSE CURSOR OVER THIS TEXT
57375775 </p>
57385776 <table>
57395777 <tr>
@@ -7918,7 +7956,8 @@
79197957 </td>
79207958 <td>4
79217959 </td>
7922 -</tr></table>
 7960+</tr>
 7961+</table>
79237962 <p>y
79247963 </p>
79257964 !! end
Index: trunk/phase3/includes/parser/Parser.php
@@ -829,8 +829,13 @@
830830 foreach ( $lines as $outLine ) {
831831 $line = trim( $outLine );
832832
833 - if ( $line === '' ) { // empty line, go to next line
834 - $out .= $outLine . "\n";
 833+ # empty line, go to next line,
 834+ # but only append \n if outside of table
 835+ if ( $line === '' ) {
 836+ $out .= $outLine;
 837+ if ( !isset( $tables[0] ) ) {
 838+ $out .= "\n";
 839+ }
835840 continue;
836841 }
837842 $firstChars = $line[0];
@@ -877,8 +882,14 @@
878883 if ( empty( $lastRow ) ) {
879884 $lastRow = NULL;
880885 }
 886+ $o = '';
881887 $curtable = array_pop( $tables );
882 - $o = $this->generateTableHTML( $curtable ) . $line;
 888+
 889+ #Add a line-ending before the table, but only if there isn't one already
 890+ if ( substr( $out, -1 ) !== "\n" ) {
 891+ $o .= "\n";
 892+ }
 893+ $o .= $this->generateTableHTML( $curtable ) . $line . "\n";
883894
884895 if ( count( $tables ) > 0 ) {
885896 $table =& $this->last( $tables );
@@ -968,7 +979,12 @@
969980 if ( isset( $tables ) && count( $tables ) > 0 ) {
970981 for ( $i = 0; $i < count( $tables ); $i++ ) {
971982 $curtable = array_pop( $tables );
972 - $out .= $this->generateTableHTML( $curtable );
 983+ $curtable = $this->generateTableHTML( $curtable );
 984+ #Add a line-ending before the table, but only if there isn't one already
 985+ if ( substr( $out, -1 ) !== "\n" && $curtable !== "" ) {
 986+ $out .= "\n";
 987+ }
 988+ $out .= $curtable;
973989 }
974990 }
975991
@@ -1018,7 +1034,7 @@
10191035 * @private
10201036 */
10211037 function generateTableHTML ( &$table ) {
1022 - $return = "\n";
 1038+ $return = "";
10231039 $return .= str_repeat( '<dl><dd>' , $table['indent'] );
10241040 $return .= '<table';
10251041 $return .= isset( $table['attributes'] ) ? $table['attributes'] : '';

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85922diebuche21:27, 12 April 2011

Status & tagging log