Browse Source

rename unclean->raw

pull/251/head
Peter Johnson 9 years ago
parent
commit
10242a8682
  1. 6
      sanitiser/_categories.js
  2. 6
      sanitiser/_details.js
  3. 8
      sanitiser/_geo_common.js
  4. 8
      sanitiser/_geo_reverse.js
  5. 8
      sanitiser/_geo_search.js
  6. 26
      sanitiser/_id.js
  7. 6
      sanitiser/_layers.js
  8. 4
      sanitiser/_size.js
  9. 6
      sanitiser/_source.js
  10. 6
      sanitiser/_text.js

6
sanitiser/_categories.js

@ -2,7 +2,7 @@
var check = require('check-types'); var check = require('check-types');
// validate inputs, convert types and apply defaults // validate inputs, convert types and apply defaults
function sanitize( unclean, clean ){ function sanitize( raw, clean ){
// error & warning messages // error & warning messages
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };
@ -11,10 +11,10 @@ function sanitize( unclean, clean ){
clean.categories = []; clean.categories = [];
// if categories string has been set // if categories string has been set
if( check.unemptyString( unclean.categories ) ){ if( check.unemptyString( raw.categories ) ){
// map input categories to valid format // map input categories to valid format
clean.categories = unclean.categories.split(',') clean.categories = raw.categories.split(',')
.map(function (cat) { .map(function (cat) {
return cat.toLowerCase().trim(); // lowercase inputs return cat.toLowerCase().trim(); // lowercase inputs
}) })

6
sanitiser/_details.js

@ -3,13 +3,13 @@ var check = require('check-types');
var DEFAULT_DETAILS_BOOL = true; var DEFAULT_DETAILS_BOOL = true;
// validate inputs, convert types and apply defaults // validate inputs, convert types and apply defaults
function sanitize( unclean, clean ){ function sanitize( raw, clean ){
// error & warning messages // error & warning messages
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };
if( !check.undefined( unclean.details ) ){ if( !check.undefined( raw.details ) ){
clean.details = isTruthy( unclean.details ); clean.details = isTruthy( raw.details );
} else { } else {
clean.details = DEFAULT_DETAILS_BOOL; clean.details = DEFAULT_DETAILS_BOOL;
} }

8
sanitiser/_geo_common.js

@ -10,15 +10,15 @@ var util = require('util'),
* bbox = left, bottom, right, top * bbox = left, bottom, right, top
* bbox = min Longitude, min Latitude, max Longitude, max Latitude * bbox = min Longitude, min Latitude, max Longitude, max Latitude
* *
* @param {object} unclean * @param {object} raw
* @param {object} clean * @param {object} clean
*/ */
function sanitize_bbox( unclean, clean ) { function sanitize_bbox( raw, clean ) {
if( !check.unemptyString( unclean.bbox ) ) { if( !check.unemptyString( raw.bbox ) ) {
return; return;
} }
var bboxArr = unclean.bbox.split( ',' ); var bboxArr = raw.bbox.split( ',' );
if( Array.isArray( bboxArr ) && bboxArr.length === 4 ) { if( Array.isArray( bboxArr ) && bboxArr.length === 4 ) {
var bbox = bboxArr.map(parseFloat); var bbox = bboxArr.map(parseFloat);

8
sanitiser/_geo_reverse.js

@ -5,18 +5,18 @@ var LAT_LON_IS_REQUIRED = true,
CIRCLE_MUST_BE_COMPLETE = false; CIRCLE_MUST_BE_COMPLETE = false;
// validate inputs, convert types and apply defaults // validate inputs, convert types and apply defaults
module.exports = function sanitize( unclean, clean ){ module.exports = function sanitize( raw, clean ){
// error & warning messages // error & warning messages
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };
try { try {
geo_common.sanitize_coord( 'lat', clean, unclean['point.lat'], LAT_LON_IS_REQUIRED ); geo_common.sanitize_coord( 'lat', clean, raw['point.lat'], LAT_LON_IS_REQUIRED );
geo_common.sanitize_coord( 'lon', clean, unclean['point.lon'], LAT_LON_IS_REQUIRED ); geo_common.sanitize_coord( 'lon', clean, raw['point.lon'], LAT_LON_IS_REQUIRED );
// boundary.circle.* is not mandatory, and only specifying radius is fine, // boundary.circle.* is not mandatory, and only specifying radius is fine,
// as point.lat/lon will be used to fill those values by default // as point.lat/lon will be used to fill those values by default
geo_common.sanitize_boundary_circle( clean, unclean, CIRCLE_IS_REQUIRED, CIRCLE_MUST_BE_COMPLETE); geo_common.sanitize_boundary_circle( clean, raw, CIRCLE_IS_REQUIRED, CIRCLE_MUST_BE_COMPLETE);
} }
catch (err) { catch (err) {
messages.errors.push( err.message ); messages.errors.push( err.message );

8
sanitiser/_geo_search.js

@ -3,15 +3,15 @@ var geo_common = require ('./_geo_common');
var LAT_LON_IS_REQUIRED = false; var LAT_LON_IS_REQUIRED = false;
// validate inputs, convert types and apply defaults // validate inputs, convert types and apply defaults
module.exports = function sanitize( unclean, clean ){ module.exports = function sanitize( raw, clean ){
// error & warning messages // error & warning messages
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };
try { try {
geo_common.sanitize_coord( 'lat', clean, unclean['focus.point.lat'], LAT_LON_IS_REQUIRED ); geo_common.sanitize_coord( 'lat', clean, raw['focus.point.lat'], LAT_LON_IS_REQUIRED );
geo_common.sanitize_coord( 'lon', clean, unclean['focus.point.lon'], LAT_LON_IS_REQUIRED ); geo_common.sanitize_coord( 'lon', clean, raw['focus.point.lon'], LAT_LON_IS_REQUIRED );
geo_common.sanitize_bbox(unclean, clean); geo_common.sanitize_bbox(raw, clean);
} }
catch (err) { catch (err) {
messages.errors.push( err.message ); messages.errors.push( err.message );

26
sanitiser/_id.js

@ -12,21 +12,21 @@ function errorMessage(fieldname, message) {
return message || 'invalid param \''+ fieldname + '\': text length, must be >0'; return message || 'invalid param \''+ fieldname + '\': text length, must be >0';
} }
function sanitize( unclean, clean ){ function sanitize( raw, clean ){
// error & warning messages // error & warning messages
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };
// 'unclean.id' can be an array!? // 'raw.id' can be an array!?
var uncleanIds = check.array( unclean.id ) ? unclean.id : [ unclean.id ]; var rawIds = check.array( raw.id ) ? raw.id : [ raw.id ];
// de-dupe ids // de-dupe ids
uncleanIds = uncleanIds.filter(function(item, pos) { rawIds = rawIds.filter(function(item, pos) {
return uncleanIds.indexOf( item ) === pos; return rawIds.indexOf( item ) === pos;
}); });
// ensure all elements are valid non-empty strings // ensure all elements are valid non-empty strings
uncleanIds = uncleanIds.filter( function( uc ){ rawIds = rawIds.filter( function( uc ){
if( !check.unemptyString( uc ) ){ if( !check.unemptyString( uc ) ){
messages.errors.push( errorMessage('id') ); messages.errors.push( errorMessage('id') );
return false; return false;
@ -37,12 +37,12 @@ function sanitize( unclean, clean ){
// init 'clean.ids' // init 'clean.ids'
clean.ids = []; clean.ids = [];
// cycle through unclean ids and set those which are valid // cycle through raw ids and set those which are valid
uncleanIds.forEach( function( uncleanId ){ rawIds.forEach( function( rawId ){
var param_index = uncleanId.indexOf(ID_DELIM); var param_index = rawId.indexOf(ID_DELIM);
var type = uncleanId.substring(0, param_index ); var type = rawId.substring(0, param_index );
var id = uncleanId.substring(param_index + 1); var id = rawId.substring(param_index + 1);
// basic format/ presence of ':' // basic format/ presence of ':'
if(param_index === -1) { if(param_index === -1) {
@ -53,11 +53,11 @@ function sanitize( unclean, clean ){
// id text // id text
if( !check.unemptyString( id ) ){ if( !check.unemptyString( id ) ){
messages.errors.push( errorMessage( uncleanId ) ); messages.errors.push( errorMessage( rawId ) );
} }
// type text // type text
if( !check.unemptyString( type ) ){ if( !check.unemptyString( type ) ){
messages.errors.push( errorMessage( uncleanId ) ); messages.errors.push( errorMessage( rawId ) );
} }
// type text must be one of the types // type text must be one of the types
if( types.indexOf( type ) === -1 ){ if( types.indexOf( type ) === -1 ){

6
sanitiser/_layers.js

@ -9,7 +9,7 @@ var ALIAS_LAYERS = ['poi', 'admin', 'address'],
ALIAS_TYPES_JOINED = ALIAS_TYPES.join(','); ALIAS_TYPES_JOINED = ALIAS_TYPES.join(',');
// validate inputs, convert types and apply defaults // validate inputs, convert types and apply defaults
function sanitize( unclean, clean ){ function sanitize( raw, clean ){
// error & warning messages // error & warning messages
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };
@ -19,10 +19,10 @@ function sanitize( unclean, clean ){
// default case (no layers specified in GET params) // default case (no layers specified in GET params)
// don't even set the from_layers key in this case // don't even set the from_layers key in this case
if( check.unemptyString( unclean.layers ) ){ if( check.unemptyString( raw.layers ) ){
// parse GET params // parse GET params
var layers = unclean.layers.split(',').map( function( layer ){ var layers = raw.layers.split(',').map( function( layer ){
return layer.toLowerCase(); // lowercase inputs return layer.toLowerCase(); // lowercase inputs
}); });

4
sanitiser/_size.js

@ -4,13 +4,13 @@ var MIN_SIZE = 1,
DEFAULT_SIZE = 10; DEFAULT_SIZE = 10;
// validate inputs, convert types and apply defaults // validate inputs, convert types and apply defaults
function sanitize( unclean, clean ){ function sanitize( raw, clean ){
// error & warning messages // error & warning messages
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };
// coercions // coercions
var _size = parseInt( unclean.size, 10 ); var _size = parseInt( raw.size, 10 );
// invalid numeric input // invalid numeric input
// @todo: this can be removed now as queries have default sizes? // @todo: this can be removed now as queries have default sizes?

6
sanitiser/_source.js

@ -5,7 +5,7 @@ var check = require('check-types'),
var ALL_SOURCES = Object.keys(sources_map), var ALL_SOURCES = Object.keys(sources_map),
ALL_SOURCES_JOINED = ALL_SOURCES.join(','); ALL_SOURCES_JOINED = ALL_SOURCES.join(',');
function sanitize( unclean, clean ) { function sanitize( raw, clean ) {
// error & warning messages // error & warning messages
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };
@ -15,9 +15,9 @@ function sanitize( unclean, clean ) {
// default case (no layers specified in GET params) // default case (no layers specified in GET params)
// don't even set the from_layers key in this case // don't even set the from_layers key in this case
if( check.unemptyString( unclean.source ) ){ if( check.unemptyString( raw.source ) ){
var sources = unclean.source.split(','); var sources = raw.source.split(',');
var invalid_sources = sources.filter(function(source) { var invalid_sources = sources.filter(function(source) {
return ALL_SOURCES.indexOf(source) === -1; return ALL_SOURCES.indexOf(source) === -1;

6
sanitiser/_text.js

@ -3,13 +3,13 @@ var check = require('check-types'),
query_parser = require('../helper/query_parser'); query_parser = require('../helper/query_parser');
// validate texts, convert types and apply defaults // validate texts, convert types and apply defaults
function sanitize( unclean, clean ){ function sanitize( raw, clean ){
// error & warning messages // error & warning messages
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };
// invalid input 'text' // invalid input 'text'
if( !check.unemptyString( unclean.text ) ){ if( !check.unemptyString( raw.text ) ){
messages.errors.push('invalid param \'text\': text length, must be >0'); messages.errors.push('invalid param \'text\': text length, must be >0');
} }
@ -17,7 +17,7 @@ function sanitize( unclean, clean ){
else { else {
// valid text // valid text
clean.text = unclean.text; clean.text = raw.text;
// parse text with query parser // parse text with query parser
clean.parsed_text = query_parser.get_parsed_address(clean.text); clean.parsed_text = query_parser.get_parsed_address(clean.text);

Loading…
Cancel
Save