Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#13548 closed bug (fixed)

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

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

Description

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});
console.log($('body').data('long-param'));

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

jsFiddle test case: http://jsfiddle.net/m_gol/6Rqwj/7/

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

Change History (8)

comment:1 Changed 7 years ago by m_gol

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

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

comment:2 Changed 7 years ago by dmethvin

Cc: Rick Waldron added

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

comment:3 Changed 7 years ago by Rick Waldron

Owner: set to Rick Waldron
Status: newassigned

Interesting. This looks like another edge case...

The property is correctly reflected when looking at the whole object: http://jsfiddle.net/rwaldron/2UcDz/

I'll look closer at this over the weekend.

ps. Dave cc'ed and simultaneously blitzed me

comment:4 Changed 7 years ago by m_gol

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...

comment:5 Changed 7 years ago by Rick Waldron

Resolution: fixed
Status: assignedclosed

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

Changeset: 3212a293695221df402317633adf63698d95efd1

comment:6 Changed 7 years ago by m_gol

Oh, that was quick, thanks! :)

comment:7 Changed 7 years ago by m_gol

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.

comment:8 Changed 7 years ago by m_gol

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

Note: See TracTickets for help on using tickets.