Bug Tracker

Modify

Ticket #9124 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

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

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

comment:1 Changed 3 years ago by dmethvin

  • Owner set to dmethvin
  • Priority changed from undecided to blocker
  • Status changed from new to assigned
  • Component changed from unfiled to data
  • Milestone changed from 1.next to 1.6.1

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

comment:2 Changed 3 years ago by John Resig

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: a5e407cafb9d398b5bf2f209ad0e8a42691bf391

comment:3 Changed 3 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 3 years ago by rwaldron

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.