mirror of https://github.com/pelias/api.git
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.
35 lines
969 B
35 lines
969 B
9 years ago
|
function sanitize( req, sanitizers, cb ){
|
||
8 years ago
|
// init an object to store clean (sanitized) input parameters if not initialized
|
||
|
req.clean = req.clean || {};
|
||
9 years ago
|
|
||
8 years ago
|
// init errors and warnings arrays if not initialized
|
||
|
req.errors = req.errors || [];
|
||
|
req.warnings = req.warnings || [];
|
||
9 years ago
|
|
||
9 years ago
|
// source of input parameters
|
||
|
// (in this case from the GET querystring params)
|
||
|
var params = req.query || {};
|
||
|
|
||
|
for (var s in sanitizers) {
|
||
|
var sanity = sanitizers[s]( params, req.clean );
|
||
|
|
||
9 years ago
|
// if errors occurred then set them
|
||
|
// on the req object.
|
||
9 years ago
|
if( sanity.errors.length ){
|
||
9 years ago
|
req.errors = req.errors.concat( sanity.errors );
|
||
|
}
|
||
|
|
||
|
// if warnings occurred then set them
|
||
|
// on the req object.
|
||
|
if( sanity.warnings.length ){
|
||
|
req.warnings = req.warnings.concat( sanity.warnings );
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
// @todo remove these args, they do not need to be passed out
|
||
|
return cb( undefined, req.clean );
|
||
9 years ago
|
}
|
||
|
|
||
|
// export function
|
||
9 years ago
|
module.exports = sanitize;
|