Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Widget: $.widget.extend(): Properly handle extending a string with an…
… object. Fixes #8713 - Passing an object as ui.resizable handles parameter does not work.
  • Loading branch information
scottgonzalez committed Oct 22, 2012
1 parent 6bedc0a commit 9b90887
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 8 additions & 5 deletions tests/unit/widget/widget_extend.js
@@ -1,5 +1,5 @@
test( "$.widget.extend()", function() {
expect( 26 );
expect( 27 );

var ret, empty, optionsWithLength, optionsWithDate, myKlass, customObject, optionsWithCustomObject, nullUndef,
target, recursive, obj, input, output,
Expand Down Expand Up @@ -76,13 +76,16 @@ test( "$.widget.extend()", function() {
ret = $.widget.extend( { foo: [] }, { foo: [0] } ); // 1907
equal( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );

ret = $.widget.extend( { foo: "1,2,3" }, { foo: [1, 2, 3] } );
strictEqual( typeof ret.foo, "object", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
ret = $.widget.extend( { foo: "1,2,3" }, { foo: [ 1, 2, 3 ] } );
deepEqual( ret.foo, [ 1, 2, 3 ], "Properly extend a string to array." );

ret = $.widget.extend( { foo: "1,2,3" }, { foo: { to: "object" } } );
deepEqual( ret.foo, { to: "object" }, "Properly extend a string to object." );

ret = $.widget.extend( { foo: "bar" }, { foo: null } );
strictEqual( typeof ret.foo, "object", "Make sure a null value doesn't crash with deep extend, for #1908" );
strictEqual( ret.foo, null, "Make sure a null value doesn't crash with deep extend, for #1908" );

obj = { foo:null };
obj = { foo: null };
$.widget.extend( obj, { foo:"notnull" } );
equal( obj.foo, "notnull", "Make sure a null value can be overwritten" );

Expand Down
6 changes: 5 additions & 1 deletion ui/jquery.ui.widget.js
Expand Up @@ -143,7 +143,11 @@ $.widget.extend = function( target ) {
for ( key in input[ inputIndex ] ) {
value = input[ inputIndex ][ key ];
if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
target[ key ] = $.isPlainObject( value ) ? $.widget.extend( {}, target[ key ], value ) : value;
if ( $.isPlainObject( value ) && $.isPlainObject( target[ key ] ) ) {
target[ key ] = $.widget.extend( {}, target[ key ], value );
} else {
target[ key ] = value;
}
}
}
}
Expand Down

0 comments on commit 9b90887

Please sign in to comment.