Feature #144 improved regex for stripping JSONP

This commit is contained in:
Yaniv Efraim 2015-02-13 11:39:02 +02:00
parent 57691e5cb6
commit 03292d9e85
4 changed files with 15 additions and 11 deletions

View File

@ -24,7 +24,7 @@
*
* @author Jos de Jong, <wjosdejong@gmail.com>
* @version 3.2.0
* @date 2015-02-11
* @date 2015-02-12
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
@ -1486,10 +1486,14 @@ return /******/ (function(modules) { // webpackBootstrap
//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"}]
if(jsonString.match(/[\da-zA-Z_-\s]+\(+\s*/)){
var jsonStringTemp = jsonString.replace(/[\da-zA-Z_-\s]+\(+\s*/,'')
jsonString = jsonStringTemp.replace(/\s*\)(?!.*[\)])[;\s]*/g,'');
var match = jsonString.match(/^\s*[\dA-z_$]+\s*\(([\s\S]*)\)\s*;?\s*$/);
if (match) {
var jsonString = match[1];
}
// if(jsonString.match(/[\da-zA-Z_-\s]+\(+\s*/)){
// var jsonStringTemp = jsonString.replace(/[\da-zA-Z_-\s]+\(+\s*/,'')
// jsonString = jsonStringTemp.replace(/\s*\)(?!.*[\)])[;\s]*/g,'');
// }
return jsonString;
};

File diff suppressed because one or more lines are too long

4
jsoneditor.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -76,9 +76,9 @@ define(function () {
//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"}]
if(jsonString.match(/[\da-zA-Z_-\s]+\(+\s*/)){
var jsonStringTemp = jsonString.replace(/[\da-zA-Z_-\s]+\(+\s*/,'')
jsonString = jsonStringTemp.replace(/\s*\)(?!.*[\)])[;\s]*/g,'');
var match = jsonString.match(/^\s*[\dA-z_$]+\s*\(([\s\S]*)\)\s*;?\s*$/);
if (match) {
var jsonString = match[1];
}
return jsonString;