commit
50bbcb87bb
2 changed files with 88 additions and 5 deletions
|
@ -3,7 +3,7 @@ var apiLogger = log4js.getLogger("API");
|
||||||
var clientLogger = log4js.getLogger("client");
|
var clientLogger = log4js.getLogger("client");
|
||||||
var formidable = require('formidable');
|
var formidable = require('formidable');
|
||||||
var apiHandler = require('../../handler/APIHandler');
|
var apiHandler = require('../../handler/APIHandler');
|
||||||
var isVarName = require('is-var-name');
|
var isValidJSONPName = require('./isValidJsonPName');
|
||||||
|
|
||||||
//This is for making an api call, collecting all post information and passing it to the apiHandler
|
//This is for making an api call, collecting all post information and passing it to the apiHandler
|
||||||
var apiCaller = function(req, res, fields) {
|
var apiCaller = function(req, res, fields) {
|
||||||
|
@ -19,7 +19,7 @@ var apiCaller = function(req, res, fields) {
|
||||||
apiLogger.info("RESPONSE, " + req.params.func + ", " + response);
|
apiLogger.info("RESPONSE, " + req.params.func + ", " + response);
|
||||||
|
|
||||||
//is this a jsonp call, if yes, add the function call
|
//is this a jsonp call, if yes, add the function call
|
||||||
if(req.query.jsonp && isVarName(req.query.jsonp))
|
if(req.query.jsonp && isValidJSONPName.check(req.query.jsonp))
|
||||||
response = req.query.jsonp + "(" + response + ")";
|
response = req.query.jsonp + "(" + response + ")";
|
||||||
|
|
||||||
res._____send(response);
|
res._____send(response);
|
||||||
|
|
83
src/node/hooks/express/isValidJSONPName.js
Normal file
83
src/node/hooks/express/isValidJSONPName.js
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
const RESERVED_WORDS = [
|
||||||
|
'abstract',
|
||||||
|
'arguments',
|
||||||
|
'await',
|
||||||
|
'boolean',
|
||||||
|
'break',
|
||||||
|
'byte',
|
||||||
|
'case',
|
||||||
|
'catch',
|
||||||
|
'char',
|
||||||
|
'class',
|
||||||
|
'const',
|
||||||
|
'continue',
|
||||||
|
'debugger',
|
||||||
|
'default',
|
||||||
|
'delete',
|
||||||
|
'do',
|
||||||
|
'double',
|
||||||
|
'else',
|
||||||
|
'enum',
|
||||||
|
'eval',
|
||||||
|
'export',
|
||||||
|
'extends',
|
||||||
|
'false',
|
||||||
|
'final',
|
||||||
|
'finally',
|
||||||
|
'float',
|
||||||
|
'for',
|
||||||
|
'function',
|
||||||
|
'goto',
|
||||||
|
'if',
|
||||||
|
'implements',
|
||||||
|
'import',
|
||||||
|
'in',
|
||||||
|
'instanceof',
|
||||||
|
'int',
|
||||||
|
'interface',
|
||||||
|
'let',
|
||||||
|
'long',
|
||||||
|
'native',
|
||||||
|
'new',
|
||||||
|
'null',
|
||||||
|
'package',
|
||||||
|
'private',
|
||||||
|
'protected',
|
||||||
|
'public',
|
||||||
|
'return',
|
||||||
|
'short',
|
||||||
|
'static',
|
||||||
|
'super',
|
||||||
|
'switch',
|
||||||
|
'synchronized',
|
||||||
|
'this',
|
||||||
|
'throw',
|
||||||
|
'throws',
|
||||||
|
'transient',
|
||||||
|
'true',
|
||||||
|
'try',
|
||||||
|
'typeof',
|
||||||
|
'var',
|
||||||
|
'void',
|
||||||
|
'volatile',
|
||||||
|
'while',
|
||||||
|
'with',
|
||||||
|
'yield'
|
||||||
|
];
|
||||||
|
|
||||||
|
const regex = /^[a-zA-Z_$][0-9a-zA-Z_$]*(?:\[(?:".+"|\'.+\'|\d+)\])*?$/;
|
||||||
|
|
||||||
|
module.exports.check = function(inputStr) {
|
||||||
|
var isValid = true;
|
||||||
|
inputStr.split(".").forEach(function(part) {
|
||||||
|
if (!regex.test(part)) {
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RESERVED_WORDS.indexOf(part) !== -1) {
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return isValid;
|
||||||
|
}
|
Loading…
Reference in a new issue