Bug Tracker

Modify

Ticket #10544 (closed bug: fixed)

Opened 3 years ago

Last modified 18 months ago

Remove ALL special meanings of "." in keys for $.fn.data

Reported by: Darsain Owned by: dmethvin
Priority: low Milestone: 1.9
Component: data Version: 1.2.6
Keywords: Cc: dmethvin
Blocking: Blocked by:

Description

$.fn.data() doesn't behave the same way how $.data() does when using a key namespacing.

Example: if you have a data key "name.key" and it doesn't exist, the $.fn.data() will return the "name" key instead, while $.data() returns undefined, which is what I'd expect to get

Test:  http://jsfiddle.net/pNCP8/3/ (test is for 1.6.4, but 1.7b2 has the same issue)

Fix:

@@ -1943,9 +1943,7 @@
 				data = dataAttr( this[0], key, data );
 			}
 
-			return data === undefined && parts[1] ?
-				this.data( parts[0] ) :
-				data;
+			return data;
 
 		} else {
 			return this.each(function() {

Now, since I see that it is deliberately coded that way, I don't know if this is a bug, or a "feature". I've asked on #jquery-dev, but after a few hours of no reply I'm just posting it here. In case of a "feature" decision, I'd like to know the resoning behind it :)

Change History

comment:1 Changed 3 years ago by addyosmani

  • Keywords needsreview added
  • Priority changed from undecided to low
  • Component changed from unfiled to data

comment:2 Changed 3 years ago by addyosmani

Our docs don't appear to state whether or not namespaced keys are officially supported, but let me find out and I'll post back on this ticket (unless someone is able to answer before that).

comment:3 Changed 3 years ago by addyosmani

  • Cc DaveMethvin, dmethvin added
  • Owner set to gnarf
  • Status changed from new to assigned

Confirmed with @gnarf that this is a bug. CC'ing DaveMethvin for further input.

comment:4 Changed 3 years ago by gnarf

  • Cc kswedberg added
  • Keywords needsdocs added

Actualy, seems I was wrong about it being a bug... I'm not sure WHY we are doing this, but it is a unit tested feature:

Unit tests are here:

 https://github.com/jquery/jquery/blob/f2c1d2e016018ba14cd3f1612f9a1803d5e1709e/test/unit/data.js#L246-283

I can't seem to find the trac ticket that details this feature.

It is currently not documented, so we should document it if we plan on keeping it around. I'm not sure how many people are using it.

Personally, I don't think we should be supporting "namespaced" data

Last edited 3 years ago by gnarf (previous) (diff)

comment:5 Changed 3 years ago by gnarf

  • Summary changed from Different behavior between $.fn.data() and $.data() with namespaced key names to Remove ALL special meanings of "." in keys for $.fn.data
  • Version changed from 1.7b2 to 1.2.6
  • Milestone changed from None to 1.8

After a discussion in IRC with timmy and dave, we have tentatively decided that the potential for dependency on this behavior is quite high, especially considering this behavior extends as far back as jQuery 1.2.6:  http://jsfiddle.net/gnarf/pNCP8/4/ We also agree that this behavior is broken, and should be removed.

Our current strategy is to mark this "namespaced data" and the special meaning the dot has in the getData and setData events as deprecated as of 1.7. We will document the current (deprecated) behavior - and then set it up for removal in 1.8.

Last edited 3 years ago by gnarf (previous) (diff)

comment:6 Changed 2 years ago by gnarf

As a workaround for the OP of this bug ticket. You can always get your key via .data()["foo.bar"]

comment:7 Changed 2 years ago by addyosmani

Following a further discussion on IRC, it appears that we *may* opt to add a notice about this being deprecated in the 1.7 release post as opposed to having it mentioned in the docs. Given that the behaviour we have now was never documented, this probably makes the most sense.

Something along the lines of 'Using data keys that have a "." in them in jQuery 1.7 and below can cause some strange behaviors. These strange behaviors are being deprecated and will be removed in 1.8.' with specific references to namespacing if we want to be technically correct :)

JohnResig had some further concerns with this which may be mentioned at the next -meeting. Will update if the resolution changes.

comment:9 Changed 2 years ago by dmethvin

  • Cc DaveMethvin removed

We're deprecating data events in 1.8 and removing them in 1.9 so this will sort itself out naturally.

comment:10 Changed 23 months ago by dmethvin

  • Cc kswedberg removed
  • Keywords needsreview needsdocs removed
  • Milestone changed from 1.8 to 1.9

To be removed in 1.9 when data events die of natural causes. They were never documented so they don't need to be un-documented.

comment:11 Changed 18 months ago by dmethvin

  • Owner changed from gnarf to dmethvin

comment:11 Changed 18 months ago by Dave Methvin

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

Fix #10544. Remove deprecated .data() event namespaced triggering.

Data events were horribly slow, never documented, and caused strange interpretation of data items with dots in them.

Changeset: e8cf41a051a62bf1f19beab1a5c1d643f121e28e

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.