Browse Source

Use groups sanitiser in sanitize_circle

pull/305/head
Julian Simioni 9 years ago
parent
commit
b315adc6aa
  1. 41
      sanitiser/_geo_common.js

41
sanitiser/_geo_common.js

@ -49,42 +49,13 @@ function sanitize_rect( key_prefix, clean, raw, bbox_is_required ) {
*/ */
function sanitize_circle( key_prefix, clean, raw, circle_is_required ) { function sanitize_circle( key_prefix, clean, raw, circle_is_required ) {
// the names we use to define the centroid sanitize_point( key_prefix, clean, raw, circle_is_required);
var mandatoryProps = [ 'lat', 'lon' ];
// count up how many fields the user actually specified
var totalFieldsSpecified = 0;
mandatoryProps.forEach( function( prop ){
if( raw.hasOwnProperty( key_prefix + '.' + prop ) ){
totalFieldsSpecified++;
}
});
// all fields specified
if( 2 === totalFieldsSpecified ) {
// reuse the coord sanitizer and set required:true so we get a fatal error if
// any one of the coords is not specified.
sanitize_coord( key_prefix + '.lat', clean, raw[ key_prefix + '.lat' ], true );
sanitize_coord( key_prefix + '.lon', clean, raw[ key_prefix + '.lon' ], true );
if( check.assigned( raw[ key_prefix + '.radius' ] ) ){ if( check.assigned( raw[ key_prefix + '.radius' ] ) ){
sanitize_coord( key_prefix + '.radius', clean, raw[ key_prefix + '.radius' ], true ); sanitize_coord( key_prefix + '.radius', clean, raw[ key_prefix + '.radius' ], true );
} sanitize_point( key_prefix, clean, raw, true);
} } else {
// fields only partially specified sanitize_point( key_prefix, clean, raw, circle_is_required);
else if( totalFieldsSpecified > 0 ){
var format1 = 'missing circle param \'%s\' requires all of: \'%s\' to be present';
throw new Error( util.format( format1, key_prefix, mandatoryProps.join('\',\'') ) );
}
// radius was specified without lat or lon
else if( raw.hasOwnProperty( key_prefix + '.radius' ) ){
var format2 = 'missing circle param \'%s\' requires all of: \'%s\' to be present';
throw new Error( util.format( format2, key_prefix, mandatoryProps.join('\',\'') ) );
}
// fields required, eg. ( totalFieldsSpecified === 0 && bbox_is_required === true )
else if( circle_is_required ){
var format3 = 'missing circle param \'%s\' requires all of: \'%s\' to be present';
throw new Error( util.format( format3, key_prefix, mandatoryProps.join('\',\'') ) );
} }
} }

Loading…
Cancel
Save