From 9dcc296a7021fe97f3a038c500c1dc1a40626941 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 23 Sep 2015 15:19:52 -0400 Subject: [PATCH] Add focus.viewport rect sanitizer to search --- sanitiser/_geo_search.js | 2 ++ test/unit/sanitiser/search.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/sanitiser/_geo_search.js b/sanitiser/_geo_search.js index badeec52..0e5ec896 100644 --- a/sanitiser/_geo_search.js +++ b/sanitiser/_geo_search.js @@ -2,6 +2,7 @@ var geo_common = require ('./_geo_common'); var LAT_LON_IS_REQUIRED = false; var RECT_IS_REQUIRED = false; var CIRCLE_IS_REQUIRED = false; +var VIEWPORT_IS_REQUIRED = false; // validate inputs, convert types and apply defaults module.exports = function sanitize( raw, clean ){ @@ -13,6 +14,7 @@ module.exports = function sanitize( raw, clean ){ geo_common.sanitize_point( 'focus.point', clean, raw, LAT_LON_IS_REQUIRED ); geo_common.sanitize_rect( 'boundary.rect', clean, raw, RECT_IS_REQUIRED ); geo_common.sanitize_circle( 'boundary.circle', clean, raw, CIRCLE_IS_REQUIRED ); + geo_common.sanitize_rect( 'focus.viewport', clean, raw, VIEWPORT_IS_REQUIRED ); } catch (err) { messages.errors.push( err.message ); diff --git a/test/unit/sanitiser/search.js b/test/unit/sanitiser/search.js index 2b171406..eed05ee6 100644 --- a/test/unit/sanitiser/search.js +++ b/test/unit/sanitiser/search.js @@ -207,6 +207,28 @@ module.exports.tests.sanitize_bounding_rect = function(test, common) { }); }; +module.exports.tests.sanitize_viewport = function(test, common) { + test('valid viewport', function(t) { + var req = { + query: { + text: 'test', + 'focus.viewport.min_lat': '37', + 'focus.viewport.max_lat': '38', + 'focus.viewport.min_lon': '-123', + 'focus.viewport.max_lon': '-122' + } + }; + sanitize(req, function() { + t.equal(req.errors[0], undefined, 'no error'); + t.equal(req.clean['focus.viewport.min_lat'], parseFloat(req.query['focus.viewport.min_lat']), 'correct min_lat in clean'); + t.equal(req.clean['focus.viewport.max_lat'], parseFloat(req.query['focus.viewport.max_lat']), 'correct max_lat in clean'); + t.equal(req.clean['focus.viewport.min_lon'], parseFloat(req.query['focus.viewport.min_lon']), 'correct min_lon in clean'); + t.equal(req.clean['focus.viewport.max_lon'], parseFloat(req.query['focus.viewport.max_lon']), 'correct max_lon in clean'); + t.end(); + }); + }); +}; + module.exports.tests.sanitize_size = function(test, common) { test('invalid size value', function(t) { var req = { query: { size: 'a', text: 'test', lat: 0, lon: 0 } };