From: Od1n Date: Wed, 8 Feb 2017 20:08:28 +0000 (+0000) Subject: mediawiki.Uri: Don't ignore options param when using default uri X-Git-Tag: 1.31.0-rc.0~4119^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=4a34c359f12e8c0d122236430c568c8e3b27af5c;p=lhc%2Fweb%2Fwiklou.git mediawiki.Uri: Don't ignore options param when using default uri Bug: T157035 Change-Id: Iae5edf996e4cd6d1dfbbffd6a915ee55d28409d3 --- diff --git a/resources/src/mediawiki/mediawiki.Uri.js b/resources/src/mediawiki/mediawiki.Uri.js index 0c47dbe0a2..95263ec451 100644 --- a/resources/src/mediawiki/mediawiki.Uri.js +++ b/resources/src/mediawiki/mediawiki.Uri.js @@ -179,7 +179,8 @@ * override each other (`true`) or automagically convert them to an array (`false`). */ function Uri( uri, options ) { - var prop, + var prop, hrefCur, + hasOptions = ( options !== undefined ), defaultUri = getDefaultUri(); options = typeof options === 'object' ? options : { strictMode: !!options }; @@ -208,8 +209,12 @@ this.query = {}; } } + } else if ( hasOptions ) { + // We didn't get a URI in the constructor, but we got options. + hrefCur = typeof documentLocation === 'string' ? documentLocation : documentLocation(); + this.parse( hrefCur, options ); } else { - // If we didn't get a URI in the constructor, use the default one. + // We didn't get a URI or options in the constructor, use the default instance. return defaultUri.clone(); } diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js index 97185fca73..242096eab1 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js @@ -178,10 +178,10 @@ ); } ); - QUnit.test( 'Constructor( empty )', 4, function ( assert ) { + QUnit.test( 'Constructor( empty[, Object ] )', 5, function ( assert ) { var testuri, MyUri, uri; - testuri = 'http://example.org/w/index.php'; + testuri = 'http://example.org/w/index.php?a=1&a=2'; MyUri = mw.UriRelative( testuri ); uri = new MyUri(); @@ -195,6 +195,9 @@ uri = new MyUri( '' ); assert.equal( uri.toString(), testuri, 'empty string' ); + + uri = new MyUri( null, { overrideKeys: true } ); + assert.deepEqual( uri.query, { a: '2' }, 'null, with options' ); } ); QUnit.test( 'Properties', 8, function ( assert ) {