Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Check for both camelized and hyphenated data property names; Fixes #9301 #403

Closed
wants to merge 1 commit into from

2 participants

Rick Waldron Timmy Willison
Rick Waldron
Collaborator

No description provided.

Timmy Willison
Collaborator

Landed in commit 0742056.

Timmy Willison timmywil closed this June 06, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
5  src/data.js
@@ -108,7 +108,10 @@ jQuery.extend({
108 108
 			return thisCache[ internalKey ] && thisCache[ internalKey ].events;
109 109
 		}
110 110
 
111  
-		return getByName ? thisCache[ jQuery.camelCase( name ) ] : thisCache;
  111
+		return getByName ? 
  112
+			// Check for both converted-to-camel and non-converted data property names
  113
+			thisCache[ jQuery.camelCase( name ) ] || thisCache[ name ] :
  114
+			thisCache;
112 115
 	},
113 116
 
114 117
 	removeData: function( elem, name, pvt /* Internal Use Only */ ) {
17  test/unit/data.js
@@ -508,3 +508,20 @@ test("jQuery.data should follow html5 specification regarding camel casing", fun
508 508
 
509 509
 	div.remove();
510 510
 });
  511
+
  512
+test("jQuery.data should not miss data with preset hyphenated property names", function() {
  513
+
  514
+	expect(2);
  515
+
  516
+	var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
  517
+		test = {
  518
+			"camelBar": "camelBar",
  519
+			"hyphen-foo": "hyphen-foo"
  520
+		};
  521
+
  522
+	div.data( test );
  523
+
  524
+	jQuery.each( test , function(i, k) {
  525
+		equal( div.data(k), k, "data with property '"+k+"' was correctly found");
  526
+	});
  527
+});
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.