From bb89db820ef4013e9590b4c6461a1edf66c8a160 Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Fri, 19 Oct 2012 12:02:11 -0700 Subject: [PATCH] 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 --- resources/mediawiki/mediawiki.util.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 ); -- 2.20.1