Browse Source

chore(geo_common): refactor bbox min/max validation

pull/1207/head
Julian Simioni 6 years ago
parent
commit
1054a634de
No known key found for this signature in database
GPG Key ID: B9EEB0C6EE0910A1
  1. 20
      sanitizer/_geo_common.js

20
sanitizer/_geo_common.js

@ -34,17 +34,15 @@ function sanitize_rect( key_prefix, clean, raw, bbox_is_required ) {
// and not present // and not present
if (!bbox_present) { return; } if (!bbox_present) { return; }
var min_lat = parseFloat( raw[key_prefix + '.' + 'min_lat'] ); // validate max is greater than min for lat and lon
var max_lat = parseFloat( raw[key_prefix + '.' + 'max_lat'] ); ['lat', 'lon'].forEach(function(dimension) {
if (min_lat > max_lat) { const max = parseFloat(raw[`${key_prefix}.max_${dimension}`]);
throw new Error( util.format( 'min_lat is larger than max_lat in \'%s\'', key_prefix ) ); const min = parseFloat(raw[`${key_prefix}.min_${dimension}`]);
}
if (max < min) {
var min_lon = parseFloat( raw[key_prefix + '.' + 'min_lon'] ); throw new Error(`min_${dimension} is larger than max_${dimension} in ${key_prefix}`);
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 ) );
}
// use sanitize_coord to set values in `clean` // use sanitize_coord to set values in `clean`
properties.forEach(function(prop) { properties.forEach(function(prop) {

Loading…
Cancel
Save