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
f61314ff
Commit
f61314ff
authored
Apr 08, 2013
by
Oleg Gaidarenko
Committed by
Rick Waldron
Apr 08, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #8335. Do not allow add data to non-elements (2.x). Closes gh-1232
parent
aadae505
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
14 deletions
+40
-14
data.js
src/data.js
+20
-6
data.js
test/unit/data.js
+20
-8
No files found.
src/data.js
View file @
f61314ff
...
@@ -14,7 +14,14 @@ var data_user, data_priv,
...
@@ -14,7 +14,14 @@ var data_user, data_priv,
rmultiDash
=
/
([
A-Z
])
/g
;
rmultiDash
=
/
([
A-Z
])
/g
;
function
Data
()
{
function
Data
()
{
this
.
cache
=
{};
// Support: Android < 4,
// Old WebKit does not have Object.preventExtensions/freeze method, return new empty object instead
Object
.
defineProperty
(
this
.
cache
=
{},
0
,
{
get
:
function
()
{
return
{};
}
});
this
.
expando
=
jQuery
.
expando
+
Math
.
random
();
this
.
expando
=
jQuery
.
expando
+
Math
.
random
();
}
}
...
@@ -22,6 +29,13 @@ Data.uid = 1;
...
@@ -22,6 +29,13 @@ Data.uid = 1;
Data
.
prototype
=
{
Data
.
prototype
=
{
key
:
function
(
owner
)
{
key
:
function
(
owner
)
{
// We can accept data for non-element nodes in modern browsers, but we should not, see #8335.
// Always return key for "freezed" object for such cases
if
(
!
this
.
accept
(
owner
)
)
{
return
0
;
}
var
descriptor
=
{},
var
descriptor
=
{},
// Check if the owner object already has a cache key
// Check if the owner object already has a cache key
unlock
=
owner
[
this
.
expando
];
unlock
=
owner
[
this
.
expando
];
...
@@ -156,6 +170,10 @@ Data.prototype = {
...
@@ -156,6 +170,10 @@ Data.prototype = {
}
}
}
}
},
},
accept
:
function
(
owner
)
{
// Do not set data on non-element because it will not be cleared (#8335).
return
owner
.
nodeType
?
owner
.
nodeType
===
1
||
owner
.
nodeType
===
9
:
true
;
},
hasData
:
function
(
owner
)
{
hasData
:
function
(
owner
)
{
return
!
jQuery
.
isEmptyObject
(
return
!
jQuery
.
isEmptyObject
(
this
.
cache
[
owner
[
this
.
expando
]
]
||
{}
this
.
cache
[
owner
[
this
.
expando
]
]
||
{}
...
@@ -181,11 +199,7 @@ data_priv = new Data();
...
@@ -181,11 +199,7 @@ data_priv = new Data();
jQuery
.
extend
({
jQuery
.
extend
({
// This is no longer relevant to jQuery core, but must remain
acceptData
:
data_user
.
accept
,
// supported for the sake of jQuery 1.9.x API surface compatibility.
acceptData
:
function
()
{
return
true
;
},
hasData
:
function
(
elem
)
{
hasData
:
function
(
elem
)
{
return
data_user
.
hasData
(
elem
)
||
data_priv
.
hasData
(
elem
);
return
data_user
.
hasData
(
elem
)
||
data_priv
.
hasData
(
elem
);
...
...
test/unit/data.js
View file @
f61314ff
...
@@ -170,14 +170,6 @@ test("jQuery.data(object/flash)", 25, function() {
...
@@ -170,14 +170,6 @@ test("jQuery.data(object/flash)", 25, function() {
dataTests
(
flash
);
dataTests
(
flash
);
});
});
test
(
"jQuery.data(comment)"
,
25
,
function
()
{
dataTests
(
document
.
createComment
(
""
)
);
});
test
(
"jQuery.data(text)"
,
25
,
function
()
{
dataTests
(
document
.
createTextNode
(
""
)
);
});
test
(
".data()"
,
function
()
{
test
(
".data()"
,
function
()
{
expect
(
5
);
expect
(
5
);
...
@@ -685,3 +677,23 @@ test(".data doesn't throw when calling selection is empty. #13551", function() {
...
@@ -685,3 +677,23 @@ test(".data doesn't throw when calling selection is empty. #13551", function() {
ok
(
false
,
e
.
message
);
ok
(
false
,
e
.
message
);
}
}
});
});
test
(
"jQuery.acceptData"
,
6
,
function
()
{
ok
(
jQuery
.
acceptData
(
document
),
"document"
);
ok
(
jQuery
.
acceptData
(
document
.
documentElement
),
"documentElement"
);
ok
(
jQuery
.
acceptData
(
{}
),
"object"
);
ok
(
!
jQuery
.
acceptData
(
document
.
createComment
(
""
)
),
"comment"
);
ok
(
!
jQuery
.
acceptData
(
document
.
createTextNode
(
""
)
),
"text"
);
ok
(
!
jQuery
.
acceptData
(
document
.
createDocumentFragment
()
),
"documentFragment"
);
});
test
(
"Check proper data removal of non-element descendants nodes (#8335)"
,
1
,
function
()
{
var
div
=
jQuery
(
"<div>text</div>"
),
text
=
div
.
contents
();
text
.
data
(
"test"
,
"test"
);
// This should be a noop.
div
.
remove
();
ok
(
!
text
.
data
(
"test"
),
"Be sure data is not stored in non-element"
);
});
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