Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure we do the malformed JSON check for all both JSON.parse and …
…new Function (this helps to create uniformity between browser implementations of JSON.parse - like where Chrome allows some malformed strings. Thanks to DBJDBJ for the heads-up.
- Loading branch information
44e6beb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's too bad we have to penalize browsers with properly validating JSON parsers. We discussed this in #jquery-ot with SuperSlex and he came with this patch (pre-yourse) which I think should be considered:
http://github.com/SlexAxton/jquery/commit/57313eb69a7c87f862440b062932e91c0e162c6c
It uses a support property to determine if data should be controlled or not.
44e6beb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These regexs should be cached.
44e6beb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://dbj.org/dbj/?p=470
44e6beb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realised the regexs don't need to be cached in this situation...
If there are a lot of commercial services using malformed JSON, could there be an ajaxSettings option to disable the strict parsing? They could just as easily get the data as text and parse it manually, but a simple option might be appreciated too.
44e6beb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally would not agree.
I would rather sort out the offending messages (JSON) than make library which will work with illegal message formats(JSON).
As I did yesterday after switching to 1.4, for one (very large) SOA implementation where I (of all people) have done some really stupid JSON ;o(
44e6beb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
John, a slight efficiency improvement perhaps inside ajax.js ? Instead of this :
get: function( url, data, callback, type ) {
// shift arguments if data argument was omited
if ( jQuery.isFunction( data ) ) {
type = type || callback;
callback = data;
data = null;
}
I would do this :
get: function( url, data, callback, type ) {
// shift arguments if data argument was omited
if ( data && jQuery.isFunction( data ) ) { // DBJ: do not call isFunction if data is null
type = type || callback;
callback = data;
data = null;
}
// DBJ: polliticaly correct JSON ;o)
return jQuery.ajax({
"type": "GET",
"url": url,
"data": data,
"success": callback,
"dataType": type
});
},
--DBJ