You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
689 B

var isObject = require('is-object');
var query_parse= require('../helper/query_parser');
10 years ago
// validate inputs, convert types and apply defaults
function sanitize( req ){
req.clean = req.clean || {};
var params= req.query;
9 years ago
// ensure the input params are a valid object
10 years ago
if( !isObject( params ) ){
params = {};
}
// input text
if('string' !== typeof params.input || !params.input.length){
9 years ago
return {
'error': true,
'message': 'invalid param \'input\': text length, must be >0'
};
}
9 years ago
req.clean.input = params.input;
req.clean.parsed_input = query_parse(params.input);
return { 'error': false };
}
// export function
9 years ago
module.exports = sanitize;