Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#9124 closed bug (fixed)

Changes to $.data illogical in certain case

Reported by: antti.kumpulainen@… Owned by: dmethvin
Priority: blocker Milestone: 1.6.1
Component: data Version: 1.6
Keywords: Cc:
Blocked by: Blocking:

Description

This applies to all browsers and version 1.6 only.

I have a test case to reproduce the error.

I'm expecting that if I use .data('foo-bar') I get the data from 'foo-bar' or 'fooBar', but NOT "randomly".

Currently if .data('foo-bar', 'something') is called, after that .data('foo-bar') returns something even if fooBar has a value.

There are two solutions:

a) Do not return camel cased version with .data('foo-bar').

b) When setting .data('foo-bar', 'something'), set the camel cased version and not the actual 'foo-bar'.

Change History (4)

comment:1 Changed 12 years ago by dmethvin

Component: unfileddata
Milestone: 1.next1.6.1
Owner: set to dmethvin
Priority: undecidedblocker
Status: newassigned

Agreed, as we discussed on IRC. It seemed like using the camel-cased name consistently would be the best approach. Thanks!

comment:2 Changed 12 years ago by John Resig

Resolution: fixed
Status: assignedclosed

Make sure that data properties with hyphens are always accessed/set using camelCase. Fixes #9124.

Changeset: a5e407cafb9d398b5bf2f209ad0e8a42691bf391

comment:3 Changed 12 years ago by pscassidy@…

I think this is counter-intuitive behaviour. Why would a user who has set a data property with "foo-bar" expect that the *only* way they can retrieve it is via "foobar".

The problem is that "foo-bar" is an illegal name in js - hence the HTML 5 spec on hyphens in data attributes.

If data is to follow the HTML 5 spec on js dataset access a better (consistent) solution would be to make hyphenated names illegal in data.

comment:4 Changed 12 years ago by Rick Waldron

There is a pull request pending to allow access via hyphenated and camel cased property keys

Note: See TracTickets for help on using tickets.