Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#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 in reply to:  description Changed 7 years ago by anonymous

Replying to anonymous:

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 a jsfiddle because their library options only support up to beta1, and beta2 was just released a few hours ago.

Sylvain Crx.

comment:2 Changed 7 years ago by Rick Waldron

Owner: set to Rick Waldron
Status: newassigned

I'll look at this tomorrow

comment:3 Changed 7 years ago by m_gol

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 7 years ago by Rick Waldron

Owner: changed from Rick Waldron to anonymous
Status: assignedpending

Thanks m_gol!

Sylvain, can you take a look at m_gol's fiddle?

comment:5 Changed 7 years ago by anonymous

Status: pendingnew

@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 7 years ago by sylvain courcoux

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 7 years ago by Rick Waldron

Owner: changed from anonymous to Rick Waldron
Status: newassigned

comment:8 Changed 7 years ago by Rick Waldron

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 7 years ago by Rick Waldron

Resolution: fixed
Status: assignedclosed

Fixes #13551. Guard against illegal data access by undefined elem-owner

Signed-off-by: Rick Waldron <waldron.rick@…>

Changeset: 692afbcc5f719392c729997eacb234c07d2a6c78

comment:10 Changed 7 years ago by sylvain courcoux

@Rick: indeed, I forgot the closing quote in the jsfiddle but overall, thank you for fixing the underlying issue so quickly. Great job!

comment:11 Changed 7 years ago by Rick Waldron

Of course and thanks for the report!

comment:12 Changed 7 years ago by Rick Waldron

#13564 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.