Skip to content

Commit

Permalink
Widget: Handle Object.create(null) for options objects
Browse files Browse the repository at this point in the history
Fixes #15179
Closes gh-1809
  • Loading branch information
scottgonzalez committed Apr 24, 2017
1 parent ef2e9ba commit b3c0a7f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion tests/unit/widget/extend.js
Expand Up @@ -5,7 +5,7 @@ define( [
], function( QUnit, $ ) {

QUnit.test( "$.widget.extend()", function( assert ) {
assert.expect( 27 );
assert.expect( 28 );

var ret, empty, optionsWithLength, optionsWithDate, myKlass, customObject, optionsWithCustomObject, nullUndef,
target, recursive, obj, input, output,
Expand Down Expand Up @@ -108,6 +108,11 @@ QUnit.test( "$.widget.extend()", function( assert ) {
assert.deepEqual( input, output, "don't clone arrays" );
input.key[ 0 ] = 10;
assert.deepEqual( input, output, "don't clone arrays" );

input = Object.create( null );
input.foo = "f";
output = $.widget.extend( {}, input );
assert.deepEqual( input, output, "Object with no prototype" );
} );

} );
3 changes: 2 additions & 1 deletion ui/widget.js
Expand Up @@ -26,6 +26,7 @@
}( function( $ ) {

var widgetUuid = 0;
var widgetHasOwnProperty = Array.prototype.hasOwnProperty;
var widgetSlice = Array.prototype.slice;

$.cleanData = ( function( orig ) {
Expand Down Expand Up @@ -183,7 +184,7 @@ $.widget.extend = function( target ) {
for ( ; inputIndex < inputLength; inputIndex++ ) {
for ( key in input[ inputIndex ] ) {
value = input[ inputIndex ][ key ];
if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
if ( widgetHasOwnProperty.call( input[ inputIndex ], key ) && value !== undefined ) {

// Clone objects
if ( $.isPlainObject( value ) ) {
Expand Down

0 comments on commit b3c0a7f

Please sign in to comment.