Browse Source

Remove checks for longitude validity.

sanitiser/_geo.js
	-Remove the code that verified `longitude` validity, to allow
	longitude values outside of the value's real range, [-180, 180].
	elasticsearch appears to handle them gracefully, so this
	resolves #56.
pull/178/head
Severyn Kozak 10 years ago committed by Julian Simioni
parent
commit
d000868800
  1. 51
      sanitiser/_geo.js

51
sanitiser/_geo.js

@ -1,3 +1,4 @@
var util = require( 'util' );
var isObject = require('is-object'); var isObject = require('is-object');
@ -46,26 +47,25 @@ function sanitize_bbox( clean, param ) {
return; return;
} }
var bbox = [];
var bboxArr = param.split( ',' ); var bboxArr = param.split( ',' );
if( Array.isArray( bboxArr ) && bboxArr.length === 4 ) { if( Array.isArray( bboxArr ) && bboxArr.length === 4 ) {
bbox = bboxArr.filter( function( latlon, index ) { var bbox = bboxArr.map( function ( latlon ){
latlon = parseFloat( latlon, 10 ); return parseFloat( latlon, 10 );
return !(lat_lon_checks[(index % 2 === 0 ? 'lon' : 'lat')].is_invalid( latlon )); });
bboxArr.forEach( function( latlon, index ) {
if( index % 2 === 1 && check_lat.is_invalid( latlon ) ){
throw new Error( 'Invalid lat: ' + latlon );
}
}); });
if( bbox.length === 4 ) { clean.bbox = {
clean.bbox = { right: Math.max( bbox[0], bbox[2] ),
right: Math.max( bbox[0], bbox[2] ), top: Math.max( bbox[1], bbox[3] ),
top: Math.max( bbox[1], bbox[3] ), left: Math.min( bbox[0], bbox[2] ),
left: Math.min( bbox[0], bbox[2] ), bottom: Math.min( bbox[1], bbox[3] )
bottom: Math.min( bbox[1], bbox[3] ) };
};
} else {
throw new Error('invalid bbox');
}
} }
} }
@ -80,13 +80,13 @@ function sanitize_bbox( clean, param ) {
function sanitize_coord( coord, clean, param, latlon_is_required ) { function sanitize_coord( coord, clean, param, latlon_is_required ) {
var value = parseFloat( param, 10 ); var value = parseFloat( param, 10 );
if ( !isNaN( value ) ) { if ( !isNaN( value ) ) {
if( lat_lon_checks[coord].is_invalid( value ) ){ if( coord === 'lat' && check_lat.is_invalid( value ) ){
throw new Error( 'invalid ' + lat_lon_checks[coord].error_msg ); throw new Error( 'invalid ' + check_lat.error_msg );
} }
clean[coord] = value; clean[coord] = value;
} }
else if (latlon_is_required) { else if (latlon_is_required) {
throw new Error('missing ' + lat_lon_checks[coord].error_msg); throw new Error( util.format( 'missing param \'%s\'', coord ) );
} }
} }
@ -97,18 +97,9 @@ function sanitize_zoom_level( clean, param ) {
} }
} }
var lat_lon_checks = { var check_lat = {
lat: { is_invalid: function is_invalid_lat( lat ){
is_invalid: function is_invalid_lat(lat) { return isNaN( lat ) || lat < -90 || lat > 90;
return isNaN( lat ) || lat < -90 || lat > 90;
},
error_msg: 'param \'lat\': must be >-90 and <90'
}, },
lon: { error_msg: 'param \'lat\': must be >-90 and <90'
is_invalid: function is_invalid_lon(lon) {
return isNaN(lon) || lon < -180 || lon > 180;
},
error_msg: 'param \'lon\': must be >-180 and <180'
}
}; };

Loading…
Cancel
Save