Skip to main content

Bug Tracker

Side navigation

#9301 closed bug (fixed)

Opened May 16, 2011 09:45PM UTC

Closed June 07, 2011 12:19AM UTC

Last modified July 19, 2011 08:24PM UTC

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:
Blocked by: Blocking:
Description

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

Attachments (0)
Change History (29)

Changed May 17, 2011 03:17AM UTC by rwaldron comment:1

component: unfiledcore
owner: → rwaldron
priority: undecidedblocker
status: newassigned

Changed May 17, 2011 03:25AM UTC by rwaldron comment:2

Changed May 22, 2011 07:27PM UTC by john comment:3

keywords: → 1.7-discuss

Nominating ticket for 1.7 discussion.

Changed May 22, 2011 08:42PM UTC by rwaldron comment:4

description: 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: #9124If 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

+1, Seems like a bug, should be fixed

Changed May 23, 2011 12:52AM UTC by jaubourg comment:5

+1, bug

Changed May 23, 2011 04:52AM UTC by timmywil comment:6

+1,

Changed May 24, 2011 09:58PM UTC by dmethvin comment:7

description: 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: #9124If 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

+1, OK, so I guess the solution is to take two stabs into the data object, one camelCase and the second camel-case?

Changed June 03, 2011 02:02PM UTC by john comment:8

description: 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: #9124If 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

+1, Seems like we should get this in 1.6.2.

Changed June 03, 2011 03:20PM UTC by rwaldron comment:9

description: 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: #9124If 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

Changed June 05, 2011 10:05PM UTC by ajpiano comment:10

+1, Buggy mc buggerson

Changed June 06, 2011 03:04PM UTC by scottgonzalez comment:11

description: 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: #9124If 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

+1

Changed June 07, 2011 12:18AM UTC by timmywil comment:12

description: 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: #9124If 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
milestone: 1.next1.6.2

Changed June 07, 2011 12:18AM UTC by timmywil comment:13

keywords: 1.7-discuss

Changed June 07, 2011 12:19AM UTC by rwldrn comment:14

resolution: → fixed
status: assignedclosed

Landing pull request 403. Check for both camelized and hyphenated data property names; Fixes #9301.

More Details:

Changeset: 07420566452622f37b01e69bbbdcbeeb5317e065

Changed June 29, 2011 07:51PM UTC by Jean-Sébastien Goupil <jsgoupil@gmail.com> comment:15

Related bug added #9700

Changed July 01, 2011 03:26PM UTC by anonymous comment:16

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/

Changed July 01, 2011 09:43PM UTC by rwaldron comment:17

Can you make a _reduced_ test case?

Changed July 01, 2011 09:51PM UTC by rwaldron comment:18

Also, per the HTML5 data-* attr spec (which users requested that jQuery follow), hyphenated attributes are accessed by their camel cased equivalent

Changed July 01, 2011 09:59PM UTC by rwaldron comment:19

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.

Changed July 05, 2011 04:20PM UTC by Adam Jenkins comment:20

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.

Changed July 05, 2011 08:01PM UTC by rwaldron comment:21

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.

Changed July 07, 2011 01:51AM UTC by Adam Jenkins <akmjenkins@gmail.com> comment:22

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')); 

Changed July 07, 2011 01:53AM UTC by Adam Jenkins <akmjenkins@gmail.com> comment:23

Replying to [comment:22 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')); 

Changed July 07, 2011 01:55AM UTC by Adam Jenkins <akmjenkins@gmail.com> comment:24

Replying to [comment:23 Adam Jenkins <akmjenkins@…>]:

Replying to [comment:22 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')); 
> 

Changed July 07, 2011 07:02PM UTC by rwaldron comment:25

#9775 is a duplicate of this ticket.

Changed July 07, 2011 07:05PM UTC by rwaldron comment:26

#9775 is a duplicate of this ticket.

Changed July 10, 2011 09:13PM UTC by rwaldron comment:27

#9792 is a duplicate of this ticket.

Changed July 19, 2011 03:39PM UTC by anonymous comment:28

Hi there,

I just downloaded 1.6.2 and data function is broken.

I just made the following test:

http://jsfiddle.net/Jb8kA/

Omar Diego Vera

Changed July 19, 2011 08:24PM UTC by rwaldron comment:29

@Omar, yes. thanks.

It will be fixed in the next release. See: https://github.com/jquery/jquery/pull/432