From 7a8422025a4aad461871b90ee27e99f397244e69 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Thu, 2 Apr 2015 11:47:55 -0400 Subject: [PATCH] latlon is a required field for reverse (updated _geo sanitizer) and added ability to filter by layers on /reverse --- sanitiser/_geo.js | 21 ++++++++++++++++----- sanitiser/reverse.js | 6 +++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/sanitiser/_geo.js b/sanitiser/_geo.js index 0b874837..2b7106af 100644 --- a/sanitiser/_geo.js +++ b/sanitiser/_geo.js @@ -1,8 +1,9 @@ // validate inputs, convert types and apply defaults -function sanitize( req ){ +function sanitize( req, latlon_is_required ){ var clean = req.clean || {}; var params= req.query; + latlon_is_required = latlon_is_required || false; // ensure the input params are a valid object if( Object.prototype.toString.call( params ) !== '[object Object]' ){ @@ -18,8 +19,8 @@ function sanitize( req ){ }; // lat - if (!isNaN(params.lat)) { - var lat = parseFloat( params.lat, 10 ); + var lat = parseFloat( params.lat, 10 ); + if (!isNaN(lat)) { if( is_invalid_lat(lat) ){ return { 'error': true, @@ -27,11 +28,16 @@ function sanitize( req ){ }; } clean.lat = lat; + } else if (latlon_is_required) { + return { + 'error': true, + 'message': 'missing param \'lat\': must be >-90 and <90' + }; } // lon - if (!isNaN(params.lon)) { - var lon = parseFloat( params.lon, 10 ); + var lon = parseFloat( params.lon, 10 ); + if (!isNaN(lon)) { if( is_invalid_lon(lon) ){ return { 'error': true, @@ -39,6 +45,11 @@ function sanitize( req ){ }; } clean.lon = lon; + } else if (latlon_is_required) { + return { + 'error': true, + 'message': 'missing param \'lon\': must be >-180 and <180' + }; } // zoom level diff --git a/sanitiser/reverse.js b/sanitiser/reverse.js index 82b96ef1..117b67d2 100644 --- a/sanitiser/reverse.js +++ b/sanitiser/reverse.js @@ -2,7 +2,11 @@ var logger = require('../src/logger'), _sanitize = require('../sanitiser/_sanitize'), sanitiser = { - latlonzoom: require('../sanitiser/_geo'), + latlonzoom: function( req ) { + var geo = require('../sanitiser/_geo'); + return geo(req, true); + }, + layers: require('../sanitiser/_layers'), size: function( req ) { var size = require('../sanitiser/_size'); return size(req, 1);