#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 10 years ago by
comment:2 Changed 10 years ago by
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 10 years ago by
Owner: | set to Rick Waldron |
---|---|
Status: | new → assigned |
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 10 years ago by
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 10 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixes #13548. .data should not miss attr() set data-* with hyphenated property names
Changeset: 3212a293695221df402317633adf63698d95efd1
comment:7 Changed 10 years ago by
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 10 years ago by
See the followup bug together with a pull request link: bug #13550
Sorry, I've messed up the code sample. Pasted below.