Opened 9 years ago
Closed 8 years ago
#14376 closed bug (migrated)
`.data()` doesn't handle the attributes with digits in the name well
Reported by: | Owned by: | Rick Waldron | |
---|---|---|---|
Priority: | low | Milestone: | 1.12/2.2 |
Component: | data | Version: | 1.10.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
version affected: any (1.10.1) browser: any (chrome) OS: any (windows 7 64bit)
For the following html
<div data-foo-42="bar"></div>
and
var div = $('div'); console.log(div.data());
javascript code I expect to see the object with one property.
Actual result: an empty object
jsfiddle: http://jsfiddle.net/nWCKt/
Change History (15)
comment:1 Changed 9 years ago by
comment:2 Changed 9 years ago by
Component: | unfiled → data |
---|---|
Milestone: | None → 1.11/2.1 |
Priority: | undecided → low |
Status: | new → open |
It seems like we shouldn't take out the hyphen unless the following char is /[a-z]/
. However that's inside jQuery.camelCase()
so making that change could affect many other situations outside data attributes.
comment:3 Changed 9 years ago by
Owner: | set to Rick Waldron |
---|---|
Status: | open → assigned |
comment:4 follow-up: 5 Changed 9 years ago by
comment:5 Changed 9 years ago by
Resolution: | → cantfix |
---|---|
Status: | assigned → closed |
https://code.google.com/p/chromium/issues/detail?id=315125&thanks=315125&ts=1383668374
...was closed as a duplicate of this: https://code.google.com/p/chromium/issues/detail?id=171175
Based on the spec:
For each name in list, for each U+002D HYPHEN-MINUS character (-) in the name that is followed by a lowercase ASCII letter, remove the U+002D HYPHEN-MINUS character (-) and replace the character that followed it by the same character converted to ASCII uppercase.
the solution would be to _not_ remove hyphens when they are immediately followed by numbers,
so that data-foo-42
would produce a key called foo-42
. Unfortunately, this is a compatibility breaking change—one that we actually have unit tests to support.
comment:7 Changed 9 years ago by
Resolution: | cantfix |
---|---|
Status: | closed → reopened |
This is one of those weird situations where we "cantfix" but we probably should... Re-opening to discuss the ultimate fate of this one at the next meeting.
comment:8 Changed 9 years ago by
Status: | reopened → open |
---|
comment:9 Changed 9 years ago by
This has been fixed in Chrome https://code.google.com/p/chromium/issues/detail?id=171175
comment:10 Changed 9 years ago by
Milestone: | 1.11/2.1 → 1.next/2.next |
---|
This is a behavior change so it won't go into 1.11/2.1, but I think we'll need to deal with it.
comment:12 follow-up: 13 Changed 9 years ago by
@malsup, the two branches seem to work the same with the OP's test case. Is there some other test case?
comment:13 Changed 9 years ago by
Replying to dmethvin:
@malsup, the two branches seem to work the same with the OP's test case. Is there some other test case?
@dmethvin See thread: https://github.com/jquery/api.jquery.com/issues/383
comment:14 Changed 9 years ago by
Milestone: | 1.next/2.next → 1.12/2.2 |
---|
comment:15 Changed 8 years ago by
Resolution: | → migrated |
---|---|
Status: | open → closed |
Migrated to https://github.com/jquery/jquery/issues/1751
Seems to be happening because we camelize the key before passing it to
dataAttr()
function.dataAttr()
then tries to reconstruct the hyphenated attribute name and does so incorrectly.Consider following example:
data-foo-bar --> fooBar --> data-foo-bar (correct)
data-foo-42 --> foo42 --> data-foo42 (incorrect)