mediawiki.Uri: Don't ignore options param when using default uri
authorOd1n <john.doe@gmail.com>
Wed, 8 Feb 2017 20:08:28 +0000 (20:08 +0000)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 9 Feb 2017 14:39:40 +0000 (14:39 +0000)
Bug: T157035
Change-Id: Iae5edf996e4cd6d1dfbbffd6a915ee55d28409d3

resources/src/mediawiki/mediawiki.Uri.js
tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js

index 0c47dbe..95263ec 100644 (file)
                 *  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();
                        }
 
index 97185fc..242096e 100644 (file)
                );
        } );
 
-       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 ) {