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
692afbcc
Commit
692afbcc
authored
Mar 04, 2013
by
Rick Waldron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #13551. Guard against illegal data access by undefined elem-owner
Signed-off-by:
Rick Waldron
<
waldron.rick@gmail.com
>
parent
91824bd2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
data.js
src/data.js
+7
-4
data.js
test/unit/data.js
+11
-0
No files found.
src/data.js
View file @
692afbcc
...
...
@@ -85,7 +85,7 @@ Data.prototype = {
// Either a valid cache is found, or will be created.
// New caches will be created and the unlock returned,
// allowing direct access to the newly created
// empty data object.
// empty data object.
A valid owner object must be provided.
var
cache
=
this
.
cache
[
this
.
key
(
owner
)
];
return
key
===
undefined
?
...
...
@@ -255,9 +255,12 @@ jQuery.fn.extend({
var
data
,
camelKey
=
jQuery
.
camelCase
(
key
);
// Get the Data...
if
(
value
===
undefined
)
{
// The calling jQuery object (element matches) is not empty
// (and therefore has an element appears at this[0]) and the
// `value` parameter was not undefined. An empty jQuery object
// will result in `undefined` for elem = this[0] which will
// throw an exception if an attempt to read a data cache is made.
if
(
elem
&&
value
===
undefined
)
{
// Attempt to get data from the cache
// with the key as-is
data
=
data_user
.
get
(
elem
,
key
);
...
...
test/unit/data.js
View file @
692afbcc
...
...
@@ -670,3 +670,14 @@ test( "JSON data- attributes can have newlines", function() {
equal
(
x
.
data
(
"some"
).
foo
,
"bar"
,
"got a JSON data- attribute with spaces"
);
x
.
remove
();
});
test
(
".data doesn't throw when calling selection is empty. #13551"
,
function
()
{
expect
(
1
);
try
{
jQuery
(
null
).
data
(
"prop"
);
ok
(
true
,
"jQuery(null).data('prop') does not throw"
);
}
catch
(
e
)
{
ok
(
false
,
e
.
message
);
}
});
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