Fix Bug 25794: Disallow multiple table captions & only keep the first
authorLeo Koppelkamm <diebuche@users.mediawiki.org>
Thu, 21 Apr 2011 07:27:05 +0000 (07:27 +0000)
committerLeo Koppelkamm <diebuche@users.mediawiki.org>
Thu, 21 Apr 2011 07:27:05 +0000 (07:27 +0000)
includes/parser/Parser.php
tests/parser/parserTests.txt

index 8bcb416..0158416 100644 (file)
@@ -913,16 +913,17 @@ class Parser {
                                }
 
                        } else if ( $firstChars  === '|+' ) {
-                               // a table caption
-                               $line = substr ( $line , 2 );
-
-                               $c = $this->getCellAttr( $line , 'caption' );
-                               $table['caption'] = array();
-                               $table['caption']['content'] = $c[0];
-                               if ( isset( $c[1] ) ) $table['caption']['attributes'] = $c[1];
-                               unset( $c );
-
-                               $output =& $table['caption'];
+                               // a table caption, but only proceed if there isn't one already
+                               if ( !isset ( $table['caption'] ) ) {
+                                       $line = substr ( $line , 2 );
+                                       
+                                       $c = $this->getCellAttr( $line , 'caption' );
+                                       $table['caption'] = array();
+                                       $table['caption']['content'] = $c[0];
+                                       if ( isset( $c[1] ) ) $table['caption']['attributes'] = $c[1];
+                                       unset( $c );
+                                       $output =& $table['caption']['content'];
+                               }
                        } else if ( $firstChars === '|' || $firstChars === '!' || $firstChars === '!+' ) {
                                // Which kind of cells are we dealing with
                                $currentTag = 'td';
index 72208fe..27e90b6 100644 (file)
@@ -1330,6 +1330,39 @@ Table with thead
 </tr></tbody>
 </table>
 
+!! end
+
+!! test
+Table with multiple captions: Only keep first
+!! input
+{|
+|+ caption 1
+|+ caption 2
+|}
+!! result
+<table>
+<caption>caption 1
+</caption>
+<tr><td></td></tr>
+</table>
+
+!! end
+
+!! test
+Table with multiline caption
+!! input
+{|
+|+ caption 1
+further caption
+|}
+!! result
+<table>
+<caption>caption 1
+further caption
+</caption>
+<tr><td></td></tr>
+</table>
+
 !! end
 !! test
 Table with multiple thead