Bug Tracker

Ticket #10194 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

Data attribute names with single dash-surrounded letters cannot be accessed by the camel-case name

Reported by: Pointy Owned by: rwaldron
Priority: blocker Milestone: 1.6.4
Component: data Version: 1.6.3
Keywords: Cc:
Blocking: Blocked by:

Description

Data attributes like "data-image-x-offset" should be accessible via ".data('imageXOffset')", but currently they cannot be. The ".camelCase()" function correctly translates the name, but the code that goes the other direction apparently mishandles this case.

Access by the dashed form of the name works of course.

Change History

comment:1 Changed 3 years ago by Pointy

More info: if the dashed form of the attribute name is used at least once for a given element, then the camel-case form subsequently works.

comment:2 Changed 3 years ago by Pointy

And here's a fiddle:  http://jsfiddle.net/99eQ8/

comment:3 Changed 3 years ago by dmethvin

  • Priority changed from undecided to blocker
  • Status changed from new to open
  • Component changed from unfiled to data
  • Milestone changed from None to 1.7

Confirmed, it's a bug in rmultiDash. Thanks ... I wish we would have been able to fix this in 1.6.3 but at this point it's a 1.7 item.

comment:5 Changed 3 years ago by rwaldron

  • Status changed from open to reopened

comment:6 Changed 3 years ago by rwaldron

  • Owner set to rwaldron
  • Status changed from reopened to assigned

comment:7 Changed 3 years ago by anonymous

Possible solution is:

rmultiDash = /\B([A-Z])/g;
key.replace( newMultiDash, '-$1' ).toLowerCase()

Because it is a single character match, the index of the starting character of the next attempted match will always be one higher than the index of the previous starting character rather than being one higher than the index of the ending character matched in the previous match.

comment:8 Changed 3 years ago by anonymous

Or I should have said "...rather than being two higher than the index of the previous starting character if the previous attempt resulted in a match".

comment:10 Changed 3 years ago by rwaldron

  • Milestone changed from 1.7 to 1.6.4

comment:10 Changed 3 years ago by rwldrn

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

Bug in rmultidash. Fixes #10194

Changeset: 8e8fa6dc1ad514b0fa20e41faddcb85693d0408a

Note: See TracTickets for help on using tickets.