-
Notifications
You must be signed in to change notification settings - Fork 20.6k
.data()
doesn't handle the attributes with digits in the name well
#1751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Comment author: ameyms 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) |
Comment author: dmethvin 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 author: rwaldron This lead to filing: https://code.google.com/p/chromium/issues/detail?id=315125&thanks=315125&ts=1383668374 |
Comment author: rwaldron ...was closed as a duplicate of this: https://code.google.com/p/chromium/issues/detail?id=171175 Based on the spec:
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 author: gnarf 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 author: rwaldron This has been fixed in Chrome https://code.google.com/p/chromium/issues/detail?id=171175 |
Comment author: dmethvin 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 author: malsup This is a breaking change when migrating from 1.9 to 2.x. |
Comment author: dmethvin @malsup, the two branches seem to work the same with the OP's test case. Is there some other test case? |
Comment author: malsup Replying to dmethvin:
@dmethvin See thread: https://github.com/jquery/api.jquery.com/issues/383 |
assert.equal( jQuery("<div>").data({ "a-b": 1 }).data( "a-b", 2 ).data( "a-b" ), 2 ) And per #1515 (comment) , we want the "Embrace HTML5" option:
|
/cc @rwaldron |
@markelog what's up? I was following this, but there hasn't been any activity lately. |
I'll grab this for 3.0, if that's alright with Rick. |
@timmywil sure, it shouldn't be too much work TBH. Mostly deleting code paths and associated tests. The tricky part is making sure that manipulation tests pass as well, since data tests exist there also |
Originally reported by zerkms@… at: http://bugs.jquery.com/ticket/14376
version affected: any (1.10.1) browser: any (chrome) OS: any (windows 7 64bit)
For the following html
and
javascript code I expect to see the object with one property.
Actual result: an empty object
jsfiddle: http://jsfiddle.net/nWCKt/
Issue reported for jQuery 1.10.2
The text was updated successfully, but these errors were encountered: