Skip to main content

Bug Tracker

Side navigation

#13548 closed bug (fixed)

Opened March 01, 2013 10:45PM UTC

Closed March 02, 2013 12:03AM UTC

Last modified March 02, 2013 01:22AM UTC

Regression: jQuery 2.0.0b2 bugs with $ handling parameters with dashes.

Reported by: m_gol Owned by: rwaldron
Priority: undecided Milestone: None
Component: unfiled Version: 2.0b2
Keywords: Cc: rwaldron
Blocked by: Blocking:

jQuery 2.0.0b2 doesn't properly set data for parameters with dashes when there's already the appropriate data-* parameter present. As a result, code:

$('body').attr('data-long-param', 'test');
$('body').data('long-param', {a: 2});

prints 'test' to the console. This breaks a lot of things in our code base...

jsFiddle test case:

This bug didn't exist in jQuery 2.0.0b1 and jQuery 1.9.1.

Attachments (0)
Change History (8)

Changed March 01, 2013 10:49PM UTC by m_gol comment:1

Sorry, I've messed up the code sample. Pasted below.

$('body').attr('data-long-param', 'test');
$('body').data('long-param', {a: 2});

Changed March 01, 2013 10:52PM UTC by dmethvin comment:2

cc: → rwaldron

Thanks for jumping on the beta so quickly! It does look like a regression to me. What's your take @rwaldron?

Changed March 01, 2013 10:58PM UTC by rwaldron comment:3

owner: → rwaldron
status: newassigned

Interesting. This looks like another edge case...

The property is correctly reflected when looking at the whole object:

I'll look closer at this over the weekend.

ps. Dave cc'ed and simultaneously blitzed me

Changed March 01, 2013 11:54PM UTC by m_gol comment:4

OK, the problem is, older jQuerys always converted data keys to camelCase; whereas in current trunk jQuery still saves the key in a camelCase version but the order in which it's being searched for on .data(key) is:

1) long-param in data cache

2) data-long-param HTML5 attribute

3) longParam in data cache

No wonder it never gets to 3 if the attribute is present...

Changed March 02, 2013 12:03AM UTC by Rick Waldron comment:5

resolution: → fixed
status: assignedclosed

Fixes #13548. .data should not miss attr() set data-* with hyphenated property names

Changeset: 3212a293695221df402317633adf63698d95efd1

Changed March 02, 2013 12:10AM UTC by m_gol comment:6

Oh, that was quick, thanks! :)

Changed March 02, 2013 12:13AM UTC by m_gol comment:7

One remark - you added the code detecting camelCase fields before checking data-* attributes but you didn't remove the code from just after this check so now it's duplicated.

Changed March 02, 2013 01:22AM UTC by m_gol comment:8

See the followup bug together with a pull request link: bug #13550