diff options
author | Dan Heberden <danheberden@gmail.com> | 2011-04-05 01:43:14 -0700 |
---|---|---|
committer | Dan Heberden <danheberden@gmail.com> | 2011-04-05 01:43:14 -0700 |
commit | a7e7dbd978b97c55a29b364fd277c4ade1ec22b6 (patch) | |
tree | 18a7ed77e9ab5927fb9b4b00fcefd0d209b302dd /src/core.js | |
parent | 2ed81b44be958b5f2b5569ab15f22bde262b4eb6 (diff) | |
download | jquery-a7e7dbd978b97c55a29b364fd277c4ade1ec22b6.tar.gz jquery-a7e7dbd978b97c55a29b364fd277c4ade1ec22b6.zip |
Bug 7587; Enhancement/1.6 Feature: Bypass regexp filter on $.parseJSON and use native thrown exceptions if window.JSON.parse is available
Diffstat (limited to 'src/core.js')
-rw-r--r-- | src/core.js | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/core.js b/src/core.js index 9312ee288..205a6e307 100644 --- a/src/core.js +++ b/src/core.js @@ -515,16 +515,18 @@ jQuery.extend({ // Make sure leading/trailing whitespace is removed (IE can't handle it) data = jQuery.trim( data ); + // Attempt to parse using the native JSON parser first + if ( window.JSON && window.JSON.parse ) { + return window.JSON.parse( data ); + } + // Make sure the incoming data is actual JSON // Logic borrowed from http://json.org/json2.js - if ( rvalidchars.test(data.replace(rvalidescape, "@") - .replace(rvalidtokens, "]") - .replace(rvalidbraces, "")) ) { - - // Try to use the native JSON parser first - return window.JSON && window.JSON.parse ? - window.JSON.parse( data ) : - (new Function("return " + data))(); + if ( rvalidchars.test( data.replace( rvalidescape, "@" ) + .replace( rvalidtokens, "]" ) + .replace( rvalidbraces, "")) ) { + + return (new Function( "return " + data ))(); } else { jQuery.error( "Invalid JSON: " + data ); |