From: Ori Livneh Date: Fri, 19 Oct 2012 19:02:11 +0000 (-0700) Subject: getParamValue defaults to current page only if url undefined X-Git-Tag: 1.31.0-rc.0~21937 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=bb89db820ef4013e9590b4c6461a1edf66c8a160;p=lhc%2Fweb%2Fwiklou.git getParamValue defaults to current page only if url undefined The danger of using || here is apparent if you consider the following case: mw.util.getParamValue( 'action', document.referrer ); If document.referrer is the empty string (as it often is), getParamValue will look up the 'action' parameter in the current URL, which is surely unintended. The solution is to use the default value if and only if the url parameter is undefined. Change-Id: Ifd949f890d2f974dacc40e549c820c434ce57f53 --- diff --git a/resources/mediawiki/mediawiki.util.js b/resources/mediawiki/mediawiki.util.js index 2928438497..4e515bc518 100644 --- a/resources/mediawiki/mediawiki.util.js +++ b/resources/mediawiki/mediawiki.util.js @@ -258,7 +258,9 @@ * @return mixed Parameter value or null. */ getParamValue: function ( param, url ) { - url = url || document.location.href; + if ( url === undefined ) { + url = document.location.href; + } // Get last match, stop at hash var re = new RegExp( '^[^#]*[&?]' + $.escapeRE( param ) + '=([^&#]*)' ), m = re.exec( url );