Bug Tracker

Opened 10 years ago

Closed 9 years ago

#6958 closed bug (duplicate)

$.extend (not deep) copying arrays by reference not cloning

Reported by: enideo Owned by:
Priority: undecided Milestone: 1.4.3
Component: core Version: 1.4.2
Keywords: extend array Cc:
Blocked by: Blocking:


BUG: as put in the title, see the attachment for the full explanation and examples.

I believe this to be a bug as the behaviour is not as desired: arguments of the extend function, other than target, can be modified if the target is later modified (they are referenced not cloned)

PROPOSED FIX: replace the following lines in the jQuery.extend function:

// Don't bring in undefined values
} else if ( copy !== undefined ) {
	target[ name ] = copy;


// Don't bring in undefined values
} else if ( copy !== undefined ) {
  target[ name ] = ( jQuery.isArray!==undefined && jQuery.isArray(copy) )
  ? target[ name ] = copy.slice(0) : target[ name ] = copy;

NOTE: it seems necessary to check for the jQuery.isArray function's existence as the jQuery.extend function is called before this has been defined. Those who are more familiar with the rest of the code may be able to come up with a better solution.

Attachments (1)

jqExtendArrayBug.html (4.2 KB) - added by enideo 10 years ago.
Example of the bug and fixes

Download all attachments as: .zip

Change History (2)

Changed 10 years ago by enideo

Attachment: jqExtendArrayBug.html added

Example of the bug and fixes

comment:1 Changed 9 years ago by dmethvin

Priority: undecided
Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.