a little JSON content validation in globalEval
The SHOUTcast 2.0 API has an issue where sometimes requests for JSON come back as XML. By adding a couple lines of code to jQuery 1.5.1 I was able to properly deal with this by throwing an error instead of having a runtime error.
I thought this may be useful for someone experiencing similar weirdness.
Line 54 in jquery-1.5.1.js:
- // JSON RegExp
- rvalidfirstchar = /^(\[|{)+/,
- ...
Around line 588 in jquery-1.5.1.js:
- // Evaluates a script in a global context
- globalEval: function( data ) {
- if ( data && rnotwhite.test(data) ) {
- // added by taber
- if ( !rvalidfirstchar.test(data.substring(0, 1)) ) {
- jQuery.error('Invalid JSON');
- return;
- }
- //end added by taber
- ...
- }
- }