* (bug 27283) SqlBagOStuff breaks PostgreSQL transactions.
* (bug 35727) mw.Api ajax() should put token parameter last.
* (bug 260) Handle <pre> overflow automatically with a scroll bar.
+* (bug 37708) mw.Uri.clone() should make a deep copy.
=== API changes in 1.20 ===
* (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
if ( typeof uri === 'string' ) {
this.parse( uri, options );
} else if ( typeof uri === 'object' ) {
- var uriObj = this;
- $.each( properties, function ( i, property ) {
- uriObj[property] = uri[property];
- } );
- if ( this.query === undefined ) {
+ // Copy data over from existing URI object
+ for ( var prop in uri ) {
+ // Only copy direct properties, not inherited ones
+ if ( uri.hasOwnProperty( prop ) ) {
+ // Deep copy object properties
+ if ( $.isArray( uri[prop] ) || $.isPlainObject( uri[prop] ) ) {
+ this[prop] = $.extend( true, {}, uri[prop] );
+ } else {
+ this[prop] = uri[prop];
+ }
+ }
+ }
+ if ( !this.query ) {
this.query = {};
}
}
test( 'Cloning', function () {
var original, clone;
- expect( 5 );
+ expect( 6 );
- original = new mw.Uri( 'http://en.wiki.local/w/api.php?action=query&foo=bar' );
+ original = new mw.Uri( 'http://foo.example.org/index.php?one=1&two=2' );
clone = original.clone();
deepEqual( clone, original, 'clone has equivalent properties' );
equal( original.toString(), clone.toString(), 'toString matches original' );
- notStrictEqual( clone, original, 'clone is not the same when compared by reference' );
+ notStrictEqual( clone, original, 'clone is a different object when compared by reference' );
- clone.host = 'fr.wiki.local';
+ clone.host = 'bar.example.org';
notEqual( original.host, clone.host, 'manipulating clone did not effect original' );
- notEqual( original.toString(), clone.toString(), 'toString no longer matches original' );
+ notEqual( original.toString(), clone.toString(), 'Stringified url no longer matches original' );
+
+ clone.query.three = 3;
+
+ deepEqual(
+ original.query,
+ { 'one': '1', 'two': '2' },
+ 'Properties is deep cloned (bug 37708)'
+ );
} );
test( 'Constructing mw.Uri from plain object', function () {