From 1054a634deed622c6d15b4583eb3a19434f287f2 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Sat, 13 Oct 2018 10:03:54 -0400 Subject: [PATCH] chore(geo_common): refactor bbox min/max validation --- sanitizer/_geo_common.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/sanitizer/_geo_common.js b/sanitizer/_geo_common.js index bec5839f..d8393a56 100644 --- a/sanitizer/_geo_common.js +++ b/sanitizer/_geo_common.js @@ -34,17 +34,15 @@ function sanitize_rect( key_prefix, clean, raw, bbox_is_required ) { // and not present if (!bbox_present) { return; } - 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 ) ); - } + // validate max is greater than min for lat and lon + ['lat', 'lon'].forEach(function(dimension) { + const max = parseFloat(raw[`${key_prefix}.max_${dimension}`]); + const min = parseFloat(raw[`${key_prefix}.min_${dimension}`]); + + if (max < min) { + throw new Error(`min_${dimension} is larger than max_${dimension} in ${key_prefix}`); + } + }); // use sanitize_coord to set values in `clean` properties.forEach(function(prop) {