Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
84d066ff
Commit
84d066ff
authored
Jul 11, 2011
by
Rick Waldron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correct non-null|undefined evaluation of data property values. Fixes #9794
parent
1886d744
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
5 deletions
+47
-5
data.js
src/data.js
+21
-5
data.js
test/unit/data.js
+26
-0
No files found.
src/data.js
View file @
84d066ff
...
@@ -33,7 +33,9 @@ jQuery.extend({
...
@@ -33,7 +33,9 @@ jQuery.extend({
return
;
return
;
}
}
var
internalKey
=
jQuery
.
expando
,
getByName
=
typeof
name
===
"string"
,
thisCache
,
var
thisCache
,
ret
,
internalKey
=
jQuery
.
expando
,
getByName
=
typeof
name
===
"string"
,
// We have to handle DOM nodes and JS objects differently because IE6-7
// We have to handle DOM nodes and JS objects differently because IE6-7
// can't GC object references properly across the DOM-JS boundary
// can't GC object references properly across the DOM-JS boundary
...
@@ -108,10 +110,24 @@ jQuery.extend({
...
@@ -108,10 +110,24 @@ jQuery.extend({
return
thisCache
[
internalKey
]
&&
thisCache
[
internalKey
].
events
;
return
thisCache
[
internalKey
]
&&
thisCache
[
internalKey
].
events
;
}
}
return
getByName
?
// Check for both converted-to-camel and non-converted data property names
// Check for both converted-to-camel and non-converted data property names
thisCache
[
jQuery
.
camelCase
(
name
)
]
||
thisCache
[
name
]
:
// If a data property was specified
thisCache
;
if
(
getByName
)
{
// First try to find the camelCased property
ret
=
thisCache
[
jQuery
.
camelCase
(
name
)
];
// Test for null|undefined property data was found
if
(
ret
==
null
)
{
// Try to find as-is property data
ret
=
thisCache
[
name
];
}
}
else
{
ret
=
thisCache
;
}
return
ret
;
},
},
removeData
:
function
(
elem
,
name
,
pvt
/* Internal Use Only */
)
{
removeData
:
function
(
elem
,
name
,
pvt
/* Internal Use Only */
)
{
...
...
test/unit/data.js
View file @
84d066ff
...
@@ -525,3 +525,29 @@ test("jQuery.data should not miss data with preset hyphenated property names", f
...
@@ -525,3 +525,29 @@ test("jQuery.data should not miss data with preset hyphenated property names", f
equal
(
div
.
data
(
k
),
k
,
"data with property '"
+
k
+
"' was correctly found"
);
equal
(
div
.
data
(
k
),
k
,
"data with property '"
+
k
+
"' was correctly found"
);
});
});
});
});
test
(
"jQuery.data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values"
,
function
()
{
var
div
=
jQuery
(
"<div/>"
,
{
id
:
"hyphened"
}).
appendTo
(
"#qunit-fixture"
),
datas
=
{
"non-empty"
:
"a string"
,
"empty-string"
:
""
,
"one-value"
:
1
,
"zero-value"
:
0
,
"an-array"
:
[],
"an-object"
:
{},
"bool-true"
:
true
,
"bool-false"
:
false
,
"some-json"
:
'{ "foo": "bar" }'
};
expect
(
18
);
jQuery
.
each
(
datas
,
function
(
key
,
val
)
{
div
.
data
(
key
,
val
);
deepEqual
(
div
.
data
(
key
),
val
,
"get: "
+
key
);
deepEqual
(
div
.
data
(
jQuery
.
camelCase
(
key
)
),
val
,
"get: "
+
jQuery
.
camelCase
(
key
)
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment