diff --git a/sanitiser/_geo_search.js b/sanitiser/_geo_search.js index 0e5ec896..8aef9b7f 100644 --- a/sanitiser/_geo_search.js +++ b/sanitiser/_geo_search.js @@ -1,3 +1,4 @@ +var check = require('check-types'); var geo_common = require ('./_geo_common'); var LAT_LON_IS_REQUIRED = false; var RECT_IS_REQUIRED = false; @@ -10,6 +11,17 @@ module.exports = function sanitize( raw, clean ){ // error & warning messages var messages = { errors: [], warnings: [] }; + // disallow specifying both focus.point and focus.viewport + if ( ( raw['focus.viewport.min_lat'] || + raw['focus.viewport.max_lat'] || + raw['focus.viewport.min_lon'] || + raw['focus.viewport.max_lon'] ) && + ( raw['focus.point.lat'] || + raw['focus.point.lon'] ) ) { + messages.errors.push( 'focus.point and focus.viewport can\'t both be set' ); + return messages; + } + try { geo_common.sanitize_point( 'focus.point', clean, raw, LAT_LON_IS_REQUIRED ); geo_common.sanitize_rect( 'boundary.rect', clean, raw, RECT_IS_REQUIRED ); diff --git a/test/unit/sanitiser/search.js b/test/unit/sanitiser/search.js index eed05ee6..4f4e2880 100644 --- a/test/unit/sanitiser/search.js +++ b/test/unit/sanitiser/search.js @@ -227,6 +227,53 @@ module.exports.tests.sanitize_viewport = function(test, common) { t.end(); }); }); + + test('error returned if focus.point and focus.viewpoint specified', function(t) { + var req = { + query: { + text: 'test', + 'focus.point.lat': '10', + 'focus.point.lon': '15', + '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], 'focus.point and focus.viewport can\'t both be set', 'no error'); + t.notOk(req.clean.hasOwnProperty('focus.viewport.min_lat'), 'clean should be empty'); + t.notOk(req.clean.hasOwnProperty('focus.viewport.max_lat'), 'clean should be empty'); + t.notOk(req.clean.hasOwnProperty('focus.viewport.min_lon'), 'clean should be empty'); + t.notOk(req.clean.hasOwnProperty('focus.viewport.max_lon'), 'clean should be empty'); + t.notOk(req.clean.hasOwnProperty('focus.point.lat'), 'clean should be empty'); + t.notOk(req.clean.hasOwnProperty('focus.point.lon'), 'clean should be empty'); + t.end(); + }); + }); + + test('error returned if focus.point and focus.viewpoint partially specified', function(t) { + var req = { + query: { + text: 'test', + 'focus.point.lat': '10', + 'focus.viewport.min_lat': '37', + 'focus.viewport.max_lon': '-122' + } + }; + + sanitize(req, function() { + t.equal(req.errors[0], 'focus.point and focus.viewport can\'t both be set', 'no error'); + t.notOk(req.clean.hasOwnProperty('focus.viewport.min_lat'), 'clean should be empty'); + t.notOk(req.clean.hasOwnProperty('focus.viewport.max_lat'), 'clean should be empty'); + t.notOk(req.clean.hasOwnProperty('focus.viewport.min_lon'), 'clean should be empty'); + t.notOk(req.clean.hasOwnProperty('focus.viewport.max_lon'), 'clean should be empty'); + t.notOk(req.clean.hasOwnProperty('focus.point.lat'), 'clean should be empty'); + t.notOk(req.clean.hasOwnProperty('focus.point.lon'), 'clean should be empty'); + t.end(); + }); + }); }; module.exports.tests.sanitize_size = function(test, common) {