8000 Widget: $.widget.extend(): Properly handle extending a string with an… · faroncoder/jquery-ui@9b90887 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b90887

Browse files
committed
Widget: $.widget.extend(): Properly handle extending a string with an object. Fixes #8713 - Passing an object as ui.resizable handles parameter does not work.
1 parent 6bedc0a commit 9b90887

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

tests/unit/widget/widget_extend.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test( "$.widget.extend()", function() {
2-
expect( 26 );
2+
expect( 27 );
33

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

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

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

85-
obj = { foo:null };
88+
obj = { foo: null };
8689
$.widget.extend( obj, { foo:"notnull" } );
8790
equal( obj.foo, "notnull", "Make sure a null value can be overwritten" );
8891

ui/jquery.ui.widget.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ $.widget.extend = function( target ) {
143143
for ( key in input[ inputIndex ] ) {
144144
value = input[ inputIndex ][ key ];
145145
if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
146-
target[ key ] = $.isPlainObject( value ) ? $.widget.extend( {}, target[ key ], value ) : value;
146+
if ( $.isPlainObject( value ) && $.isPlainObject( target[ key ] ) ) {
147+
target[ key ] = $.widget.extend( {}, target[ key ], value );
148+
} else {
149+
target[ key ] = value;
150+
}
147151
}
148152
}
149153
}

0 commit comments

Comments
 (0)
0