#13551 closed bug (fixed)
.data() exception on jquery 2.0 beta2 when .data() isn't set
Reported by: | anonymous | Owned by: | Rick Waldron |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | git |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Hi,
Just put in jquery 2.0 b2 in my script and I get an exception.
$('#SomeElement').data('d');
This line breaks if there's no data set for that element. Can't create s jsfiddle because their library options only support beta1 and beta2 was just released a few hours ago.
Sylvain.
Change History (12)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
Owner: | set to Rick Waldron |
---|---|
Status: | new → assigned |
I'll look at this tomorrow
comment:3 Changed 10 years ago by
You can create the jsFiddle, just choose "No-Library (pure JS)" in Frameworks and add an external dependency to jQuery.
Anyway, I can't reproduce the problem, it works fine here: http://jsfiddle.net/m_gol/tZy7G/
comment:4 Changed 10 years ago by
Owner: | changed from Rick Waldron to anonymous |
---|---|
Status: | assigned → pending |
Thanks m_gol!
Sylvain, can you take a look at m_gol's fiddle?
comment:5 Changed 10 years ago by
Status: | pending → new |
---|
@m_gol: I can see that it works in your jsfiddle but it wasn't working in my code when I made the switch to beta2. I changed my code around to avoid the problem but what I can say is that everything worked fine except that line. My code is about 15,000 lines with a call to jquery every other line long so it's pretty involved.
comment:6 Changed 10 years ago by
Ok, I got to repro. The problem was occurring because the element hadn't been generated at the time the code was running when the page was initiating.
Here's your jsfidde with beta2 http://jsfiddle.net/tZy7G/4/
Here's the jsfiddle with beta1 http://jsfiddle.net/2Qbhv/1/
As you can see, in beta1 it doesn't throw the exception but in beta2 it does.
comment:7 Changed 10 years ago by
Owner: | changed from anonymous to Rick Waldron |
---|---|
Status: | new → assigned |
comment:8 Changed 10 years ago by
Just a heads up...
$('#some_element).data('d')
That throws in the beta2 example, because it's syntactically invalid—missing the closing quote at the end of "#some_element"
After correcting that, the issue you reported is confirmed. Patch to follow
comment:9 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixes #13551. Guard against illegal data access by undefined elem-owner
Signed-off-by: Rick Waldron <[email protected]…>
Changeset: 692afbcc5f719392c729997eacb234c07d2a6c78
comment:10 Changed 10 years ago by
@Rick: indeed, I forgot the closing quote in the jsfiddle but overall, thank you for fixing the underlying issue so quickly. Great job!
Replying to anonymous: