getParamValue defaults to current page only if url undefined
authorOri Livneh <ori@wikimedia.org>
Fri, 19 Oct 2012 19:02:11 +0000 (12:02 -0700)
committerOri Livneh <ori@wikimedia.org>
Sat, 20 Oct 2012 00:10:48 +0000 (17:10 -0700)
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

index 2928438..4e515bc 100644 (file)
                 * @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 );