diff --git a/src/js/util.js b/src/js/util.js index 4331926..9ede6fd 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -68,6 +68,16 @@ exports.sanitize = function (jsString) { return $1 + '"' + $2 + '"' + $3; }); + jsonString = jsonString.replace(/\/\*(.|[\r\n])*?\*\//g,'');//Remove all code comments + + //If JSON starts with a function (Carachters/digist/"_-"), remove this function. + //This is usefull for "stripping" JSONP objects to become JSON + //For example: function_12321321 ( [{"a":"b"}] ); => [{"a":"b"}] + var match = jsonString.match(/^\s*[\dA-z_$]+\s*\(([\s\S]*)\)\s*;?\s*$/); + if (match) { + var jsonString = match[1]; + } + return jsonString; };