jquery / codeorigin.jquery.com

jQuery CDN
https://releases.jquery.com
Other
57 stars 605 forks source link

The ‘$.extend’ function deal circular references cause stack explosion #75

Closed timeless1406 closed 3 years ago

timeless1406 commented 3 years ago

Test Code var obj = { a: 1, b: undefined, c: null, d: true, e: new Date('2019-12-24'), f: new RegExp('\\w+'), g: NaN, h: Symbol("foo"), i: { total:12, list:[{name:'小明',age:34},{name:'小红',age:23}] }, j: function(param) { console.log(param); } }; obj.k = obj; var result = {}; $.extend(true, result, obj); jquery: v3.6.0

My thinking: jQuery only considers ‘option[key]’ reference to target, and does not consider the reference to the ‘option’; My solution: Add conditional judgment:copy === options if ( name === "__proto__" || target === copy || copy === options) { continue; } Then running is OK.

mgol commented 3 years ago

This is a repo for the https://code.jquery.com/ website, not for jQuery itself. I see you already created https://github.com/jquery/jquery/issues/4860 so I'm just going to close this one.

timeless1406 commented 3 years ago

OK, Thanks for you reply!