Commit 94d925cd authored by jeresig's avatar jeresig

Make sure leading whitespace is trimmed for parseJSON. Fixes #6031.

parent 8b86004f
...@@ -480,6 +480,9 @@ jQuery.extend({ ...@@ -480,6 +480,9 @@ jQuery.extend({
if ( typeof data !== "string" || !data ) { if ( typeof data !== "string" || !data ) {
return null; return null;
} }
// Make sure leading/trailing whitespace is removed (IE can't handle it)
data = jQuery.trim( data );
// Make sure the incoming data is actual JSON // Make sure the incoming data is actual JSON
// Logic borrowed from http://json.org/json2.js // Logic borrowed from http://json.org/json2.js
......
...@@ -807,7 +807,7 @@ test("jQuery.proxy", function(){ ...@@ -807,7 +807,7 @@ test("jQuery.proxy", function(){
}); });
test("jQuery.parseJSON", function(){ test("jQuery.parseJSON", function(){
expect(7); expect(8);
equals( jQuery.parseJSON(), null, "Nothing in, null out." ); equals( jQuery.parseJSON(), null, "Nothing in, null out." );
equals( jQuery.parseJSON( null ), null, "Nothing in, null out." ); equals( jQuery.parseJSON( null ), null, "Nothing in, null out." );
...@@ -815,6 +815,8 @@ test("jQuery.parseJSON", function(){ ...@@ -815,6 +815,8 @@ test("jQuery.parseJSON", function(){
same( jQuery.parseJSON("{}"), {}, "Plain object parsing." ); same( jQuery.parseJSON("{}"), {}, "Plain object parsing." );
same( jQuery.parseJSON('{"test":1}'), {"test":1}, "Plain object parsing." ); same( jQuery.parseJSON('{"test":1}'), {"test":1}, "Plain object parsing." );
same( jQuery.parseJSON('\n{"test":1}'), {"test":1}, "Make sure leading whitespaces are handled." );
try { try {
jQuery.parseJSON("{a:1}"); jQuery.parseJSON("{a:1}");
...@@ -829,4 +831,4 @@ test("jQuery.parseJSON", function(){ ...@@ -829,4 +831,4 @@ test("jQuery.parseJSON", function(){
} catch( e ) { } catch( e ) {
ok( true, "Test malformed JSON string." ); ok( true, "Test malformed JSON string." );
} }
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment