mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Core: Prevent Object.prototype pollution for $.extend( true, ... )
Closes gh-4333
This commit is contained in:
parent
669f720edc
commit
753d591aea
@ -158,8 +158,9 @@ jQuery.extend = jQuery.fn.extend = function() {
|
||||
for ( name in options ) {
|
||||
copy = options[ name ];
|
||||
|
||||
// Prevent Object.prototype pollution
|
||||
// Prevent never-ending loop
|
||||
if ( target === copy ) {
|
||||
if ( name === "__proto__" || target === copy ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1062,6 +1062,13 @@ QUnit.test( "jQuery.extend(true,{},{a:[], o:{}}); deep copy with array, followed
|
||||
assert.ok( !Array.isArray( result.object ), "result.object wasn't paved with an empty array" );
|
||||
} );
|
||||
|
||||
QUnit.test( "jQuery.extend( true, ... ) Object.prototype pollution", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
jQuery.extend( true, {}, JSON.parse( "{\"__proto__\": {\"devMode\": true}}" ) );
|
||||
assert.ok( !( "devMode" in {} ), "Object.prototype not polluted" );
|
||||
} );
|
||||
|
||||
QUnit.test( "jQuery.each(Object,Function)", function( assert ) {
|
||||
assert.expect( 23 );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user