Browse Source

Verify min and max longitude and latitude

Otherwise this can potentially lead to a fairly weird Elasticsearch error mentioned in https://github.com/pelias/pelias/issues/656
pull/1050/head
Peter Backx 7 years ago committed by Julian Simioni
parent
commit
f16565df9e
No known key found for this signature in database
GPG Key ID: 6DAD08919FDBF563
  1. 12
      sanitizer/_geo_common.js
  2. 19
      test/unit/sanitizer/_geo_common.js

12
sanitizer/_geo_common.js

@ -39,6 +39,18 @@ function sanitize_rect( key_prefix, clean, raw, bbox_is_required ) {
properties.forEach(function(prop) { properties.forEach(function(prop) {
sanitize_coord(prop, clean, raw, true); sanitize_coord(prop, clean, raw, true);
}); });
var min_lat = parseFloat( raw[key_prefix + '.' + 'min_lat'] );
var max_lat = parseFloat( raw[key_prefix + '.' + 'max_lat'] );
if (min_lat > max_lat) {
throw new Error( util.format( 'min_lat is larger than max_lat in \'%s\'', key_prefix ) );
}
var min_lon = parseFloat( raw[key_prefix + '.' + 'min_lon'] );
var max_lon = parseFloat( raw[key_prefix + '.' + 'max_lon'] );
if (min_lon > max_lon) {
throw new Error( util.format( 'min_lon is larger than max_lon in \'%s\'', key_prefix ) );
}
} }
/** /**

19
test/unit/sanitizer/_geo_common.js

@ -216,8 +216,8 @@ module.exports.tests.rect = function(test, common) {
test('valid rect quad', function (t) { test('valid rect quad', function (t) {
var clean = {}; var clean = {};
var params = { var params = {
'boundary.rect.min_lat': -40.659, 'boundary.rect.min_lat': -41.614,
'boundary.rect.max_lat': -41.614, 'boundary.rect.max_lat': -40.659,
'boundary.rect.min_lon': 174.612, 'boundary.rect.min_lon': 174.612,
'boundary.rect.max_lon': 176.333 'boundary.rect.max_lon': 176.333
}; };
@ -283,6 +283,21 @@ module.exports.tests.rect = function(test, common) {
t.end(); t.end();
}); });
test('invalid rect - max/min switched', function (t) {
var clean = {};
var params = {
'boundary.rect.max_lat': 52.2387,
'boundary.rect.max_lon': 14.1367,
'boundary.rect.min_lat': 52.7945,
'boundary.rect.min_lon': 12.6398
};
var mandatory = false;
t.throws( function() {
sanitize.sanitize_rect( 'boundary.rect', clean, params, mandatory );
});
t.end();
});
}; };
module.exports.tests.circle = function(test, common) { module.exports.tests.circle = function(test, common) {

Loading…
Cancel
Save