Opened 13 years ago
Closed 13 years ago
#4830 closed bug (duplicate)
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.
Duplicate of #4578, should be fixed in 1.3.3.