]> source.dussan.org Git - jquery.git/commitdiff
Bug 7587; Enhancement/1.6 Feature: Bypass regexp filter on $.parseJSON and use native...
authorDan Heberden <danheberden@gmail.com>
Tue, 5 Apr 2011 08:43:14 +0000 (01:43 -0700)
committerDan Heberden <danheberden@gmail.com>
Tue, 5 Apr 2011 08:43:14 +0000 (01:43 -0700)
src/core.js
test/unit/ajax.js

index 9312ee2889978aa3e3c8987a7d12df05f705953b..205a6e307d1cdbfdf427d598b2793341c9ed0ae4 100644 (file)
@@ -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 );
index 7c572a32cfa228bbcd66dea9aa4e435975962bfe..e9c7a00c58da9329c30e43942f52f94ef48995c4 100644 (file)
@@ -1600,7 +1600,7 @@ test("jQuery.ajax() - malformed JSON", function() {
                },
                error: function(xhr, msg, detailedMsg) {
                        equals( "parsererror", msg, "A parse error occurred." );
-                       ok( /^Invalid JSON/.test(detailedMsg), "Detailed parsererror message provided" );
+                       ok( /^(Invalid|SyntaxError|exception)/i.test(detailedMsg), "Detailed parsererror message provided" );
                        start();
                }
        });