Ticket #9301 (closed bug: fixed)
Setting data() via an object with hyphenated keys create inaccessible data.
| Reported by: | mdawaffe | Owned by: | rwaldron |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.6.2 |
| Component: | core | Version: | 1.6.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description (last modified by timmywil) (diff)
If an element's data is set via an object with a hyphenated key, that key becomes inaccessible.
Test case: http://jsfiddle.net/V8y7X/
Related and caused by: #9124
Change History
comment:1 Changed 2 years ago by rwaldron
- Owner set to rwaldron
- Priority changed from undecided to blocker
- Status changed from new to assigned
- Component changed from unfiled to core
comment:2 Changed 2 years ago by rwaldron
Further reduction: http://jsfiddle.net/rwaldron/Azjar/
comment:3 Changed 2 years ago by john
- Keywords 1.7-discuss added
Nominating ticket for 1.7 discussion.
comment:4 Changed 2 years ago by rwaldron
- Description modified (diff)
+1, Seems like a bug, should be fixed
comment:7 Changed 2 years ago by dmethvin
- Description modified (diff)
+1, OK, so I guess the solution is to take two stabs into the data object, one camelCase and the second camel-case?
comment:8 Changed 2 years ago by john
- Description modified (diff)
+1, Seems like we should get this in 1.6.2.
comment:10 Changed 2 years ago by ajpiano
+1, Buggy mc buggerson
comment:12 Changed 2 years ago by timmywil
- Description modified (diff)
- Milestone changed from 1.next to 1.6.2
comment:14 Changed 2 years ago by rwldrn
- Status changed from assigned to closed
- Resolution set to fixed
Landing pull request 403. Check for both camelized and hyphenated data property names; Fixes #9301.
More Details:
comment:15 Changed 2 years ago by Jean-Sébastien Goupil <jsgoupil@…>
Related bug added #9700
comment:16 Changed 2 years ago by anonymous
I am not sure this is fixed. Or this fixed created more issues.
There is something wrong with .data with using numerical data.
Here is a jsFiddle showing the issue. You can remove the resource and test in the previous version. http://jsfiddle.net/UhMxP/
comment:17 Changed 2 years ago by rwaldron
Can you make a _reduced_ test case?
comment:18 Changed 2 years ago by rwaldron
Also, per the HTML5 data-* attr spec (which users requested that jQuery follow), hyphenated attributes are accessed by their camel cased equivalent
comment:19 Changed 2 years ago by rwaldron
This is really bizarre, I just tried to create a test case out of this fiddle:
http://jsfiddle.net/rwaldron/6L5cs/
...and the tests pass perfectly using the current upstream master codebase.
comment:20 Changed 23 months ago by Adam Jenkins
This is not fixed at all....if anything, it's now broken worse.
I wrote a plugin that used simple (string) data keys like .data('gs-offset') that work in jQuery <1.6.2 but not in v1.6.2. When I remove the hyphens on them all and use v1.6.2, they 'work' again, but this creates a horrendous backwards compatibility problem.
This needs to be fixed ASAP.
comment:21 Changed 23 months ago by rwaldron
Adam, Can you post a link to your plugin's code? That would help be understand what the difference beween our test suite and your real-world use case is so I can narrow down where I've gotten it wrong.
comment:22 follow-up: ↓ 23 Changed 23 months ago by Adam Jenkins <akmjenkins@…>
No need for the plugin, a much simple demonstration will do:
$(body).data('nohyphen','good').data('has-hypen','bad');
console.log($(body).data('nohyphen'));
console.log($(body).data('has-hyphen'));
comment:23 in reply to: ↑ 22 ; follow-up: ↓ 24 Changed 23 months ago by Adam Jenkins <akmjenkins@…>
Replying to Adam Jenkins <akmjenkins@…>:
No need for the plugin, a much simple demonstration will do:
$(body).data('nohyphen','good').data('has-hypen','bad'); console.log($(body).data('nohyphen')); console.log($(body).data('has-hyphen'));
I obviously made some a spelling mistake in the above code, should be:
$(body).data('nohyphen','good').data('has-hyphen','bad');
console.log($(body).data('nohyphen'));
console.log($(body).data('has-hyphen'));
comment:24 in reply to: ↑ 23 Changed 23 months ago by Adam Jenkins <akmjenkins@…>
Replying to Adam Jenkins <akmjenkins@…>:
Replying to Adam Jenkins <akmjenkins@…>:
No need for the plugin, a much simple demonstration will do:
$(body).data('nohyphen','good').data('has-hypen','bad'); console.log($(body).data('nohyphen')); console.log($(body).data('has-hyphen'));
And this is obviously fine, I must have made another spelling error when testing it out locally....I'll post the plugin code shortly.
I obviously made some a spelling mistake in the above code, should be:
$(body).data('nohyphen','good').data('has-hyphen','bad'); console.log($(body).data('nohyphen')); console.log($(body).data('has-hyphen'));
comment:25 Changed 23 months ago by rwaldron
#9775 is a duplicate of this ticket.
comment:26 Changed 23 months ago by rwaldron
#9775 is a duplicate of this ticket.
comment:27 Changed 23 months ago by rwaldron
#9792 is a duplicate of this ticket.
comment:28 Changed 23 months ago by anonymous
Hi there,
I just downloaded 1.6.2 and data function is broken. I just made the following test:
Omar Diego Vera
comment:29 Changed 23 months ago by rwaldron
@Omar, yes. thanks.
It will be fixed in the next release. See: https://github.com/jquery/jquery/pull/432
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
