Skip to main content

Bug Tracker

Side navigation

#4830 closed bug (duplicate)

Opened June 29, 2009 09:13PM UTC

Closed June 30, 2009 01:58AM UTC

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:
Blocked by: Blocking:
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.

Attachments (0)
Change History (1)

Changed June 30, 2009 01:58AM UTC by dmethvin comment:1

resolution: → duplicate
status: newclosed

Duplicate of #4578, should be fixed in 1.3.3.