#9301 closed bug (fixed)
Setting data() via an object with hyphenated keys create inaccessible data.
Reported by: | mdawaffe | Owned by: | Rick Waldron |
---|---|---|---|
Priority: | blocker | Milestone: | 1.6.2 |
Component: | core | Version: | 1.6.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description (last modified by )
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 (29)
comment:1 Changed 12 years ago by
Component: | unfiled → core |
---|---|
Owner: | set to Rick Waldron |
Priority: | undecided → blocker |
Status: | new → assigned |
comment:2 Changed 12 years ago by
comment:4 Changed 12 years ago by
Description: | modified (diff) |
---|
+1, Seems like a bug, should be fixed
comment:7 Changed 12 years ago by
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 12 years ago by
Description: | modified (diff) |
---|
+1, Seems like we should get this in 1.6.2.
comment:9 Changed 12 years ago by
Description: | modified (diff) |
---|
comment:12 Changed 12 years ago by
Description: | modified (diff) |
---|---|
Milestone: | 1.next → 1.6.2 |
comment:13 Changed 12 years ago by
Keywords: | 1.7-discuss removed |
---|
comment:14 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Landing pull request 403. Check for both camelized and hyphenated data property names; Fixes #9301.
More Details:
comment:16 Changed 12 years ago by
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:18 Changed 12 years ago by
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 12 years ago by
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 12 years ago by
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 12 years ago by
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 12 years ago by
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 follow-up: 24 Changed 12 years ago by
Replying to Adam Jenkins <[email protected]…>:
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 Changed 12 years ago by
Replying to Adam Jenkins <[email protected]…>:
Replying to Adam Jenkins <[email protected]…>:
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:28 Changed 12 years ago by
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 12 years ago by
@Omar, yes. thanks.
It will be fixed in the next release. See: https://github.com/jquery/jquery/pull/432
Further reduction: http://jsfiddle.net/rwaldron/Azjar/