* 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 };
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();
}
);
} );
- 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();
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 ) {