Skip to content

Commit

Permalink
Feature josdejong#144 improved regex for stripping JSONP
Browse files Browse the repository at this point in the history
  • Loading branch information
yanivefraim committed Feb 13, 2015
1 parent 57691e5 commit 03292d9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
14 changes: 9 additions & 5 deletions jsoneditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Jos de Jong, <[email protected]>
* @version 3.2.0
* @date 2015-02-11
* @date 2015-02-12
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
Expand Down Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion jsoneditor.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions jsoneditor.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ 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;
};

Expand Down

0 comments on commit 03292d9

Please sign in to comment.