mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Fix #14101: $().data() should be undefined, not null
- Backported 30eee925db
for 1.x
This commit is contained in:
parent
3c968ce65d
commit
075763b71a
@ -272,8 +272,7 @@ jQuery.extend({
|
|||||||
|
|
||||||
jQuery.fn.extend({
|
jQuery.fn.extend({
|
||||||
data: function( key, value ) {
|
data: function( key, value ) {
|
||||||
var i, name,
|
var i, name, data,
|
||||||
data = null,
|
|
||||||
elem = this[0],
|
elem = this[0],
|
||||||
attrs = elem && elem.attributes;
|
attrs = elem && elem.attributes;
|
||||||
|
|
||||||
@ -319,7 +318,7 @@ jQuery.fn.extend({
|
|||||||
|
|
||||||
// Gets one value
|
// Gets one value
|
||||||
// Try to fetch any internally stored data first
|
// Try to fetch any internally stored data first
|
||||||
elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : null;
|
elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
removeData: function( key ) {
|
removeData: function( key ) {
|
||||||
|
@ -164,6 +164,12 @@ test("jQuery.acceptData", function() {
|
|||||||
ok( !jQuery.acceptData( document.createTextNode("") ), "text" );
|
ok( !jQuery.acceptData( document.createTextNode("") ), "text" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// attempting to access the data of an undefined jQuery element should be undefined
|
||||||
|
test("jQuery().data() === undefined (#14101)", 2, function() {
|
||||||
|
strictEqual(jQuery().data(), undefined);
|
||||||
|
strictEqual(jQuery().data("key"), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
test(".data()", function() {
|
test(".data()", function() {
|
||||||
expect(5);
|
expect(5);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user