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. 35
      sanitiser/_geo.js

35
sanitiser/_geo.js

@ -1,3 +1,4 @@
var util = require( 'util' );
var isObject = require('is-object');
@ -46,26 +47,25 @@ function sanitize_bbox( clean, param ) {
return;
}
var bbox = [];
var bboxArr = param.split( ',' );
if( Array.isArray( bboxArr ) && bboxArr.length === 4 ) {
bbox = bboxArr.filter( function( latlon, index ) {
latlon = parseFloat( latlon, 10 );
return !(lat_lon_checks[(index % 2 === 0 ? 'lon' : 'lat')].is_invalid( latlon ));
var bbox = bboxArr.map( function ( latlon ){
return parseFloat( latlon, 10 );
});
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 = {
right: Math.max( bbox[0], bbox[2] ),
top: Math.max( bbox[1], bbox[3] ),
left: Math.min( bbox[0], bbox[2] ),
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 ) {
var value = parseFloat( param, 10 );
if ( !isNaN( value ) ) {
if( lat_lon_checks[coord].is_invalid( value ) ){
throw new Error( 'invalid ' + lat_lon_checks[coord].error_msg );
if( coord === 'lat' && check_lat.is_invalid( value ) ){
throw new Error( 'invalid ' + check_lat.error_msg );
}
clean[coord] = value;
}
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 = {
lat: {
is_invalid: function is_invalid_lat(lat) {
var check_lat = {
is_invalid: function is_invalid_lat( lat ){
return isNaN( lat ) || lat < -90 || lat > 90;
},
error_msg: 'param \'lat\': must be >-90 and <90'
},
lon: {
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