root / drupal7 / sites / all / libraries / flexslider-2.5.0 / bower_components / jquery / src / ajax / parseJSON.js @ 0aee3c58
1 |
define([ |
---|---|
2 |
"../core"
|
3 |
], function( jQuery ) {
|
4 |
|
5 |
var rvalidtokens = /(,)|(\[|{)|(}|])|"(?:[^"\\\r\n]|\\["\\\/bfnrt]|\\u[\da-fA-F]{4})*"\s*:?|true|false|null|-?(?!0\d)\d+(?:\.\d+|)(?:[eE][+-]?\d+|)/g; |
6 |
|
7 |
jQuery.parseJSON = function( data ) { |
8 |
// Attempt to parse using the native JSON parser first
|
9 |
if ( window.JSON && window.JSON.parse ) {
|
10 |
// Support: Android 2.3
|
11 |
// Workaround failure to string-cast null input
|
12 |
return window.JSON.parse( data + "" ); |
13 |
} |
14 |
|
15 |
var requireNonComma,
|
16 |
depth = null,
|
17 |
str = jQuery.trim( data + "" );
|
18 |
|
19 |
// Guard against invalid (and possibly dangerous) input by ensuring that nothing remains
|
20 |
// after removing valid tokens
|
21 |
return str && !jQuery.trim( str.replace( rvalidtokens, function( token, comma, open, close ) { |
22 |
|
23 |
// Force termination if we see a misplaced comma
|
24 |
if ( requireNonComma && comma ) {
|
25 |
depth = 0;
|
26 |
} |
27 |
|
28 |
// Perform no more replacements after returning to outermost depth
|
29 |
if ( depth === 0 ) { |
30 |
return token;
|
31 |
} |
32 |
|
33 |
// Commas must not follow "[", "{", or ","
|
34 |
requireNonComma = open || comma; |
35 |
|
36 |
// Determine new depth
|
37 |
// array/object open ("[" or "{"): depth += true - false (increment)
|
38 |
// array/object close ("]" or "}"): depth += false - true (decrement)
|
39 |
// other cases ("," or primitive): depth += true - true (numeric cast)
|
40 |
depth += !close - !open; |
41 |
|
42 |
// Remove this token
|
43 |
return ""; |
44 |
}) ) ? |
45 |
( Function( "return " + str ) )() :
|
46 |
jQuery.error( "Invalid JSON: " + data );
|
47 |
}; |
48 |
|
49 |
return jQuery.parseJSON;
|
50 |
|
51 |
}); |