Skip to content

Commit b3c0a7f

Browse files
committed
Widget: Handle Object.create(null) for options objects
Fixes #15179 Closes jquerygh-1809
1 parent ef2e9ba commit b3c0a7f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

tests/unit/widget/extend.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ define( [
55
], function( QUnit, $ ) {
66

77
QUnit.test( "$.widget.extend()", function( assert ) {
8-
assert.expect( 27 );
8+
assert.expect( 28 );
99

1010
var ret, empty, optionsWithLength, optionsWithDate, myKlass, customObject, optionsWithCustomObject, nullUndef,
1111
target, recursive, obj, input, output,
@@ -108,6 +108,11 @@ QUnit.test( "$.widget.extend()", function( assert ) {
108108
assert.deepEqual( input, output, "don't clone arrays" );
109109
input.key[ 0 ] = 10;
110110
assert.deepEqual( input, output, "don't clone arrays" );
111+
112+
input = Object.create( null );
113+
input.foo = "f";
114+
output = $.widget.extend( {}, input );
115+
assert.deepEqual( input, output, "Object with no prototype" );
111116
} );
112117

113118
} );

ui/widget.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
}( function( $ ) {
2727

2828
var widgetUuid = 0;
29+
var widgetHasOwnProperty = Array.prototype.hasOwnProperty;
2930
var widgetSlice = Array.prototype.slice;
3031

3132
$.cleanData = ( function( orig ) {
@@ -183,7 +184,7 @@ $.widget.extend = function( target ) {
183184
for ( ; inputIndex < inputLength; inputIndex++ ) {
184185
for ( key in input[ inputIndex ] ) {
185186
value = input[ inputIndex ][ key ];
186-
if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
187+
if ( widgetHasOwnProperty.call( input[ inputIndex ], key ) && value !== undefined ) {
187188

188189
// Clone objects
189190
if ( $.isPlainObject( value ) ) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy