From 217a5c1049deabc713229eb35a2089c47909ec5a Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Thu, 2 Apr 2015 16:07:36 -0400 Subject: [PATCH] seperating suggest and search sanitizers because suggest requires geoBias (lat/lon) until ES 2.0.0 lands. --- app.js | 2 +- sanitiser/search.js | 26 ++++++++++++++++++++++++++ sanitiser/suggest.js | 5 ++++- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 sanitiser/search.js diff --git a/app.js b/app.js index 047aa903..49d07b94 100644 --- a/app.js +++ b/app.js @@ -12,7 +12,7 @@ app.use( require('./middleware/jsonp') ); var sanitisers = {}; sanitisers.doc = require('./sanitiser/doc'); sanitisers.suggest = require('./sanitiser/suggest'); -sanitisers.search = sanitisers.suggest; +sanitisers.search = require('./sanitiser/search'); sanitisers.coarse = require('./sanitiser/coarse'); sanitisers.reverse = require('./sanitiser/reverse'); diff --git a/sanitiser/search.js b/sanitiser/search.js new file mode 100644 index 00000000..1748846a --- /dev/null +++ b/sanitiser/search.js @@ -0,0 +1,26 @@ + +var logger = require('../src/logger'), + _sanitize = require('../sanitiser/_sanitize'), + sanitizers = { + input: require('../sanitiser/_input'), + size: require('../sanitiser/_size'), + layers: require('../sanitiser/_layers'), + latlonzoom: require('../sanitiser/_geo') + }; + +var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); }; + +// export sanitize for testing +module.exports.sanitize = sanitize; + +// middleware +module.exports.middleware = function( req, res, next ){ + sanitize( req, function( err, clean ){ + if( err ){ + res.status(400); // 400 Bad Request + return next(err); + } + req.clean = clean; + next(); + }); +}; diff --git a/sanitiser/suggest.js b/sanitiser/suggest.js index 06288019..1897dcb8 100644 --- a/sanitiser/suggest.js +++ b/sanitiser/suggest.js @@ -5,7 +5,10 @@ var logger = require('../src/logger'), input: require('../sanitiser/_input'), size: require('../sanitiser/_size'), layers: require('../sanitiser/_layers'), - latlonzoom: require('../sanitiser/_geo') + latlonzoom: function( req ) { + var geo = require('../sanitiser/_geo'); + return geo(req, true); + } }; var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); };