Make sure leading whitespace is trimmed for parseJSON. Fixes #6031.
This commit is contained in:
parent
8b86004f9c
commit
94d925cd46
2 changed files with 7 additions and 2 deletions
|
@ -481,6 +481,9 @@ jQuery.extend({
|
||||||
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
|
||||||
if ( /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
|
if ( /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
|
||||||
|
|
|
@ -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." );
|
||||||
|
@ -816,6 +816,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}");
|
||||||
ok( false, "Test malformed JSON string." );
|
ok( false, "Test malformed JSON string." );
|
||||||
|
|
Loading…
Add table
Reference in a new issue