mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Fix #14459: Use jQuery.parseJSON instead of JSON.parse
This commit is contained in:
parent
95d1192d53
commit
ced9d155f0
@ -36,7 +36,7 @@ function dataAttr( elem, key, data ) {
|
||||
data === "null" ? null :
|
||||
// Only convert to a number if it doesn't change the string
|
||||
+data + "" === data ? +data :
|
||||
rbrace.test( data ) ? JSON.parse( data ) :
|
||||
rbrace.test( data ) ? jQuery.parseJSON( data ) :
|
||||
data;
|
||||
} catch( e ) {}
|
||||
|
||||
|
@ -262,7 +262,6 @@ test("data-* attributes", function() {
|
||||
var prop, i, l, metadata, elem,
|
||||
obj, obj2, check, num, num2,
|
||||
parseJSON = jQuery.parseJSON,
|
||||
nativeParse = typeof JSON !== "undefined" && JSON.parse,
|
||||
div = jQuery("<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>");
|
||||
@ -319,17 +318,11 @@ test("data-* attributes", function() {
|
||||
equal( child.data("other"), "test", "Make sure value was pulled in properly from a .data()." );
|
||||
|
||||
// attribute parsing
|
||||
i = l = 0;
|
||||
i = 0;
|
||||
jQuery.parseJSON = function() {
|
||||
i++;
|
||||
return parseJSON.apply( this, arguments );
|
||||
};
|
||||
if ( nativeParse ) {
|
||||
JSON.parse = function() {
|
||||
l++;
|
||||
return nativeParse.apply( this, arguments );
|
||||
};
|
||||
}
|
||||
|
||||
child
|
||||
.attr("data-true", "true")
|
||||
@ -377,12 +370,9 @@ test("data-* attributes", function() {
|
||||
strictEqual( child.data("space"), " ", "Whitespace string read from attribute");
|
||||
strictEqual( child.data("null"), null, "Primitive null 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;
|
||||
if ( nativeParse ) {
|
||||
JSON.parse = nativeParse;
|
||||
}
|
||||
child.remove();
|
||||
|
||||
// tests from metadata plugin
|
||||
|
Loading…
Reference in New Issue
Block a user