(bug 43964) Invalid value of "link" parameter in <gallery> no longer produces a fatal...
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Mon, 14 Jan 2013 21:09:26 +0000 (22:09 +0100)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Wed, 23 Jan 2013 06:40:27 +0000 (07:40 +0100)
Also added a test for this just in case someone wants to break this :)

Change-Id: I2782cf1a45b574eb5fd69b1c1be561e7bdaef59e

RELEASE-NOTES-1.21
includes/parser/Parser.php
tests/parser/parserTests.txt

index 01ff993..a2949a0 100644 (file)
@@ -83,7 +83,7 @@ production.
   in MW 1.20 (saving preferences using Special:Preferences cleared any
   additional fields) and which has been disabled in 1.20.1 as a part of
   a security fix (bug 42202).
-* Added the ability to limit the wall clock time used by shell processes, 
+* Added the ability to limit the wall clock time used by shell processes,
   as well as the CPU time. Configurable with $wgMaxShellWallClockTime.
 
 === Bug fixes in 1.21 ===
@@ -152,6 +152,8 @@ production.
 * wfMerge() now works if $wgDiff3 contains spaces
 * (bug 43052) mediawiki.action.view.dblClickEdit.dblClickEdit should trigger
   ca-edit click instead opening URL directly.
+* (bug 43964) Invalid value of "link" parameter in <gallery> no longer produces
+  a fatal error.
 
 === API changes in 1.21 ===
 * prop=revisions can now report the contentmodel and contentformat.
index d47ccb9..478bd6d 100644 (file)
@@ -4988,13 +4988,17 @@ class Parser {
                                                $alt = $this->stripAltText( $match, false );
                                        }
                                        elseif( $match = $magicWordLink->matchVariableStartToEnd( $parameterMatch ) ){
-                                               $link = strip_tags($this->replaceLinkHoldersText($match));
+                                               $linkValue = strip_tags( $this->replaceLinkHoldersText( $match ) );
                                                $chars = self::EXT_LINK_URL_CLASS;
                                                $prots = $this->mUrlProtocols;
                                                //check to see if link matches an absolute url, if not then it must be a wiki link.
-                                               if(!preg_match( "/^($prots)$chars+$/u", $link)){
-                                                       $localLinkTitle = Title::newFromText($link);
-                                                       $link = $localLinkTitle->getLocalURL();
+                                               if ( preg_match( "/^($prots)$chars+$/u", $linkValue ) ) {
+                                                       $link = $linkValue;
+                                               } else {
+                                                       $localLinkTitle = Title::newFromText( $linkValue );
+                                                       if ( $localLinkTitle !== null ) {
+                                                               $link = $localLinkTitle->getLocalURL();
+                                                       }
                                                }
                                        }
                                        else {
index 63c9e65..8a9791b 100644 (file)
@@ -12675,6 +12675,23 @@ File:foobar.jpg|caption|alt=galleryalt|link=" onclick="alert('malicious javascri
 
 !! end
 
+!!test
+Gallery with invalid title as link (bug 43964)
+!! input
+<gallery>
+File:foobar.jpg|link=<
+</gallery>
+!! result
+<ul class="gallery">
+               <li class="gallerybox" style="width: 155px"><div style="width: 155px">
+                       <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" /></a></div></div>
+                       <div class="gallerytext">
+                       </div>
+               </div></li>
+</ul>
+
+!! end
+
 !!test
 Language parser function
 !! input