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
ced9d155
Commit
ced9d155
authored
Oct 28, 2013
by
Richard Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #14459: Use jQuery.parseJSON instead of JSON.parse
parent
95d1192d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
13 deletions
+3
-13
data.js
src/data.js
+1
-1
data.js
test/unit/data.js
+2
-12
No files found.
src/data.js
View file @
ced9d155
...
@@ -36,7 +36,7 @@ function dataAttr( elem, key, data ) {
...
@@ -36,7 +36,7 @@ function dataAttr( elem, key, data ) {
data
===
"null"
?
null
:
data
===
"null"
?
null
:
// Only convert to a number if it doesn't change the string
// Only convert to a number if it doesn't change the string
+
data
+
""
===
data
?
+
data
:
+
data
+
""
===
data
?
+
data
:
rbrace
.
test
(
data
)
?
JSON
.
parse
(
data
)
:
rbrace
.
test
(
data
)
?
jQuery
.
parseJSON
(
data
)
:
data
;
data
;
}
catch
(
e
)
{}
}
catch
(
e
)
{}
...
...
test/unit/data.js
View file @
ced9d155
...
@@ -262,7 +262,6 @@ test("data-* attributes", function() {
...
@@ -262,7 +262,6 @@ test("data-* attributes", function() {
var
prop
,
i
,
l
,
metadata
,
elem
,
var
prop
,
i
,
l
,
metadata
,
elem
,
obj
,
obj2
,
check
,
num
,
num2
,
obj
,
obj2
,
check
,
num
,
num2
,
parseJSON
=
jQuery
.
parseJSON
,
parseJSON
=
jQuery
.
parseJSON
,
nativeParse
=
typeof
JSON
!==
"undefined"
&&
JSON
.
parse
,
div
=
jQuery
(
"<div>"
),
div
=
jQuery
(
"<div>"
),
child
=
jQuery
(
"<div data-myobj='old data' data-ignored=
\"
DOM
\"
data-other='test'></div>"
),
child
=
jQuery
(
"<div data-myobj='old data' data-ignored=
\"
DOM
\"
data-other='test'></div>"
),
dummy
=
jQuery
(
"<div data-myobj='old data' data-ignored=
\"
DOM
\"
data-other='test'></div>"
);
dummy
=
jQuery
(
"<div data-myobj='old data' data-ignored=
\"
DOM
\"
data-other='test'></div>"
);
...
@@ -319,17 +318,11 @@ test("data-* attributes", function() {
...
@@ -319,17 +318,11 @@ test("data-* attributes", function() {
equal
(
child
.
data
(
"other"
),
"test"
,
"Make sure value was pulled in properly from a .data()."
);
equal
(
child
.
data
(
"other"
),
"test"
,
"Make sure value was pulled in properly from a .data()."
);
// attribute parsing
// attribute parsing
i
=
l
=
0
;
i
=
0
;
jQuery
.
parseJSON
=
function
()
{
jQuery
.
parseJSON
=
function
()
{
i
++
;
i
++
;
return
parseJSON
.
apply
(
this
,
arguments
);
return
parseJSON
.
apply
(
this
,
arguments
);
};
};
if
(
nativeParse
)
{
JSON
.
parse
=
function
()
{
l
++
;
return
nativeParse
.
apply
(
this
,
arguments
);
};
}
child
child
.
attr
(
"data-true"
,
"true"
)
.
attr
(
"data-true"
,
"true"
)
...
@@ -377,12 +370,9 @@ test("data-* attributes", function() {
...
@@ -377,12 +370,9 @@ test("data-* attributes", function() {
strictEqual
(
child
.
data
(
"space"
),
" "
,
"Whitespace string read from attribute"
);
strictEqual
(
child
.
data
(
"space"
),
" "
,
"Whitespace string read from attribute"
);
strictEqual
(
child
.
data
(
"null"
),
null
,
"Primitive null read from attribute"
);
strictEqual
(
child
.
data
(
"null"
),
null
,
"Primitive null read from attribute"
);
strictEqual
(
child
.
data
(
"string"
),
"test"
,
"Typical string read from attribute"
);
strictEqual
(
child
.
data
(
"string"
),
"test"
,
"Typical string read from attribute"
);
equal
(
i
||
l
,
2
,
"Correct number of JSON parse attempts when reading from attributes"
);
equal
(
i
,
2
,
"Correct number of JSON parse attempts when reading from attributes"
);
jQuery
.
parseJSON
=
parseJSON
;
jQuery
.
parseJSON
=
parseJSON
;
if
(
nativeParse
)
{
JSON
.
parse
=
nativeParse
;
}
child
.
remove
();
child
.
remove
();
// tests from metadata plugin
// tests from metadata plugin
...
...
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