Bug Tracker

Modify

Ticket #4830 (closed bug: duplicate)

Opened 4 years ago

Last modified 4 years ago

Passing undefined to jQuery when called with remove silently deletes the data store

Reported by: Keith Bentrup Owned by:
Priority: critical Milestone: 1.4
Component: unfiled Version: 1.3.2
Keywords: jquery document data store undefined Cc:
Blocking: Blocked by:

Description

From  http://stackoverflow.com/questions/1058359/is-this-right-a-jquery-bug-that-erases-the-data-store:

Compare this:

$('body').data('x',1); $(thisx).remove(); console.log($('body').data('x'));

to this:

$('body').data('x',1); $(this.x).remove(); console.log($('body').data('x'));

If thisx is undefined, it will immediatly throw a reference error. If x is an undefined property of this, jQuery will return the document as it's result set instead. Next jQuery will attempt to remove your document (which it can't), but before doing that it will remove all data attached to any child element of the document. Thus, wiping out your data store.

Note: this can be any element reference or object. You only need to have jQuery attempt to access an undefined property.

Possible solution: before selector = selector | | document; throw an error if arguments == 1 and that argument is undefined.

See first link for complete details and discussion.

Change History

comment:1 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to duplicate

Duplicate of #4578, should be fixed in 1.3.3.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.