Browse Source

fix lat error

pull/21/head
Peter Johnson 10 years ago
parent
commit
03a60831b4
  1. 8
      sanitiser/_latlonzoom.js
  2. 4
      test/unit/sanitiser/sanitise.js

8
sanitiser/_latlonzoom.js

@ -11,11 +11,11 @@ function sanitize( req ){
// lat // lat
var lat = parseFloat( params.lat, 10 ); var lat = parseFloat( params.lat, 10 );
if( isNaN( lat ) || lat < 0 || lat > 90 ){ if( isNaN( lat ) || lat < -90 || lat > 90 ){
return { return {
'error': true, 'error': true,
'message': 'invalid param \'lat\': must be >0 and <90' 'message': 'invalid param \'lat\': must be >-90 and <90'
} };
} }
clean.lat = lat; clean.lat = lat;
@ -25,7 +25,7 @@ function sanitize( req ){
return { return {
'error': true, 'error': true,
'message': 'invalid param \'lon\': must be >-180 and <180' 'message': 'invalid param \'lon\': must be >-180 and <180'
} };
} }
clean.lon = lon; clean.lon = lon;

4
test/unit/sanitiser/sanitise.js

@ -50,13 +50,13 @@ module.exports.tests.sanitize_input = function(test, common) {
module.exports.tests.sanitize_lat = function(test, common) { module.exports.tests.sanitize_lat = function(test, common) {
var lats = { var lats = {
invalid: [ -1, -45, -90, 91, 120, 181 ], invalid: [ -181, -120, -91, 91, 120, 181 ],
valid: [ 0, 45, 90, -0, '0', '45', '90' ] valid: [ 0, 45, 90, -0, '0', '45', '90' ]
}; };
lats.invalid.forEach( function( lat ){ lats.invalid.forEach( function( lat ){
test('invalid lat', function(t) { test('invalid lat', function(t) {
sanitize({ input: 'test', lat: lat, lon: 0 }, function( err, clean ){ sanitize({ input: 'test', lat: lat, lon: 0 }, function( err, clean ){
t.equal(err, 'invalid param \'lat\': must be >0 and <90', 'invalid latitude'); t.equal(err, 'invalid param \'lat\': must be >-90 and <90', 'invalid latitude');
t.equal(clean, undefined, 'clean not set'); t.equal(clean, undefined, 'clean not set');
t.end(); t.end();
}); });

Loading…
Cancel
Save