Skip to main content

Bug Tracker

Side navigation

#13551 closed bug (fixed)

Opened March 02, 2013 02:58AM UTC

Closed March 04, 2013 12:40AM UTC

Last modified March 04, 2013 03:33PM UTC

.data() exception on jquery 2.0 beta2 when .data() isn't set

Reported by: anonymous Owned by: rwaldron
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.

Attachments (0)
Change History (12)

Changed March 02, 2013 03:03AM UTC by anonymous comment:1

Replying to [ticket:13551 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.

Changed March 02, 2013 06:28AM UTC by rwaldron comment:2

owner: → rwaldron
status: newassigned

I'll look at this tomorrow

Changed March 02, 2013 11:06AM UTC by m_gol comment:3

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/

Changed March 02, 2013 05:53PM UTC by rwaldron comment:4

owner: rwaldronanonymous
status: assignedpending

Thanks m_gol!

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

Changed March 03, 2013 11:08PM UTC by anonymous comment:5

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.

Changed March 03, 2013 11:23PM UTC by sylvain courcoux comment:6

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.

Changed March 03, 2013 11:47PM UTC by rwaldron comment:7

owner: anonymousrwaldron
status: newassigned

Changed March 04, 2013 12:11AM UTC by rwaldron comment:8

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

Changed March 04, 2013 12:40AM UTC by Rick Waldron comment:9

resolution: → fixed
status: assignedclosed

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

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

Changeset: 692afbcc5f719392c729997eacb234c07d2a6c78

Changed March 04, 2013 01:21AM UTC by sylvain courcoux comment:10

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

Changed March 04, 2013 01:39AM UTC by rwaldron comment:11

Of course and thanks for the report!

Changed March 04, 2013 03:33PM UTC by rwaldron comment:12

#13564 is a duplicate of this ticket.