git.asbjorn.biz
/
jquery.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8b86004
)
Make sure leading whitespace is trimmed for parseJSON. Fixes #6031.
author
jeresig
<jeresig@gmail.com>
Sat, 13 Feb 2010 07:14:23 +0000
(
02:14
-0500)
committer
jeresig
<jeresig@gmail.com>
Sat, 13 Feb 2010 07:14:23 +0000
(
02:14
-0500)
src/core.js
patch
|
blob
|
history
test/unit/core.js
patch
|
blob
|
history
diff --git
a/src/core.js
b/src/core.js
index
02d8269
..
9fa311d
100644
(file)
--- a/
src/core.js
+++ b/
src/core.js
@@
-480,6
+480,9
@@
jQuery.extend({
if ( typeof data !== "string" || !data ) {
return null;
}
if ( typeof data !== "string" || !data ) {
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
// Logic borrowed from http://json.org/json2.js
// Make sure the incoming data is actual JSON
// Logic borrowed from http://json.org/json2.js
diff --git
a/test/unit/core.js
b/test/unit/core.js
index
4576ab8
..
d8aba16
100644
(file)
--- a/
test/unit/core.js
+++ b/
test/unit/core.js
@@
-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 ), null, "Nothing in, null out." );
equals( jQuery.parseJSON(), null, "Nothing in, null out." );
equals( jQuery.parseJSON( null ), null, "Nothing in, null out." );
@@
-815,6
+815,8
@@
test("jQuery.parseJSON", function(){
same( jQuery.parseJSON("{}"), {}, "Plain object parsing." );
same( jQuery.parseJSON('{"test":1}'), {"test":1}, "Plain object parsing." );
same( jQuery.parseJSON("{}"), {}, "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 {
jQuery.parseJSON("{a:1}");
try {
jQuery.parseJSON("{a:1}");
@@
-829,4
+831,4
@@
test("jQuery.parseJSON", function(){
} catch( e ) {
ok( true, "Test malformed JSON string." );
}
} catch( e ) {
ok( true, "Test malformed JSON string." );
}
-});
\ No newline at end of file
+});