Bug 7587; Enhancement/1.6 Feature: Bypass regexp filter on $.parseJSON and use native thrown exceptions if window.JSON.parse is available
This commit is contained in:
parent
2ed81b44be
commit
a7e7dbd978
2 changed files with 10 additions and 8 deletions
16
src/core.js
16
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, "")) ) {
|
||||
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))();
|
||||
return (new Function( "return " + data ))();
|
||||
|
||||
} else {
|
||||
jQuery.error( "Invalid JSON: " + data );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue