From 3763d0b5031a09ec0b0ad8706461d10f9b61a850 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Thu, 22 Sep 2016 16:29:28 -0400 Subject: [PATCH] renamed `sanitise` -> `sanitize` --- routes/v1.js | 28 ++++---- sanitiser/autocomplete.js | 34 ---------- sanitiser/reverse.js | 28 -------- sanitiser/search.js | 26 -------- {sanitiser => sanitizer}/_boundary_country.js | 0 {sanitiser => sanitizer}/_categories.js | 0 .../_deprecate_quattroshapes.js | 0 {sanitiser => sanitizer}/_details.js | 0 {sanitiser => sanitizer}/_flag_bool.js | 0 {sanitiser => sanitizer}/_geo_autocomplete.js | 0 {sanitiser => sanitizer}/_geo_common.js | 2 +- {sanitiser => sanitizer}/_geo_reverse.js | 0 {sanitiser => sanitizer}/_geo_search.js | 0 {sanitiser => sanitizer}/_groups.js | 0 {sanitiser => sanitizer}/_ids.js | 0 .../_single_scalar_parameters.js | 0 {sanitiser => sanitizer}/_size.js | 0 .../_sources_and_layers.js | 4 +- {sanitiser => sanitizer}/_targets.js | 0 {sanitiser => sanitizer}/_text.js | 0 {sanitiser => sanitizer}/_text_addressit.js | 0 {sanitiser => sanitizer}/_tokenizer.js | 0 sanitizer/autocomplete.js | 34 ++++++++++ {sanitiser => sanitizer}/nearby.js | 8 +-- {sanitiser => sanitizer}/place.js | 10 +-- sanitizer/reverse.js | 28 ++++++++ {sanitiser => sanitizer}/sanitizeAll.js | 0 sanitizer/search.js | 26 ++++++++ {sanitiser => sanitizer}/search_fallback.js | 4 +- {sanitiser => sanitizer}/wrap.js | 0 test/unit/run.js | 48 +++++++------- .../_boundary_country.js | 2 +- .../{sanitiser => sanitizer}/_categories.js | 2 +- .../_deprecate_quattroshapes.js | 2 +- .../{sanitiser => sanitizer}/_flag_bool.js | 2 +- .../{sanitiser => sanitizer}/_geo_common.js | 2 +- .../{sanitiser => sanitizer}/_geo_reverse.js | 2 +- test/unit/{sanitiser => sanitizer}/_groups.js | 2 +- test/unit/{sanitiser => sanitizer}/_ids.js | 2 +- test/unit/{sanitiser => sanitizer}/_layers.js | 2 +- .../_single_scalar_parameters.js | 2 +- test/unit/{sanitiser => sanitizer}/_size.js | 2 +- .../unit/{sanitiser => sanitizer}/_sources.js | 2 +- .../_sources_and_layers.js | 2 +- test/unit/{sanitiser => sanitizer}/_text.js | 22 +++---- .../_text_addressit.js | 2 +- .../{sanitiser => sanitizer}/_tokenizer.js | 40 ++++++------ test/unit/{sanitiser => sanitizer}/_truthy.js | 2 +- .../{sanitiser => sanitizer}/autocomplete.js | 8 +-- test/unit/{sanitiser => sanitizer}/nearby.js | 8 +-- test/unit/{sanitiser => sanitizer}/place.js | 8 +-- test/unit/{sanitiser => sanitizer}/reverse.js | 8 +-- .../{sanitiser => sanitizer}/sanitizeAll.js | 2 +- test/unit/{sanitiser => sanitizer}/search.js | 52 +++++++-------- .../search_fallback.js | 64 +++++++++---------- test/unit/{sanitiser => sanitizer}/wrap.js | 2 +- 56 files changed, 262 insertions(+), 262 deletions(-) delete mode 100644 sanitiser/autocomplete.js delete mode 100644 sanitiser/reverse.js delete mode 100644 sanitiser/search.js rename {sanitiser => sanitizer}/_boundary_country.js (100%) rename {sanitiser => sanitizer}/_categories.js (100%) rename {sanitiser => sanitizer}/_deprecate_quattroshapes.js (100%) rename {sanitiser => sanitizer}/_details.js (100%) rename {sanitiser => sanitizer}/_flag_bool.js (100%) rename {sanitiser => sanitizer}/_geo_autocomplete.js (100%) rename {sanitiser => sanitizer}/_geo_common.js (98%) rename {sanitiser => sanitizer}/_geo_reverse.js (100%) rename {sanitiser => sanitizer}/_geo_search.js (100%) rename {sanitiser => sanitizer}/_groups.js (100%) rename {sanitiser => sanitizer}/_ids.js (100%) rename {sanitiser => sanitizer}/_single_scalar_parameters.js (100%) rename {sanitiser => sanitizer}/_size.js (100%) rename {sanitiser => sanitizer}/_sources_and_layers.js (89%) rename {sanitiser => sanitizer}/_targets.js (100%) rename {sanitiser => sanitizer}/_text.js (100%) rename {sanitiser => sanitizer}/_text_addressit.js (100%) rename {sanitiser => sanitizer}/_tokenizer.js (100%) create mode 100644 sanitizer/autocomplete.js rename {sanitiser => sanitizer}/nearby.js (65%) rename {sanitiser => sanitizer}/place.js (54%) create mode 100644 sanitizer/reverse.js rename {sanitiser => sanitizer}/sanitizeAll.js (100%) create mode 100644 sanitizer/search.js rename {sanitiser => sanitizer}/search_fallback.js (89%) rename {sanitiser => sanitizer}/wrap.js (100%) rename test/unit/{sanitiser => sanitizer}/_boundary_country.js (98%) rename test/unit/{sanitiser => sanitizer}/_categories.js (98%) rename test/unit/{sanitiser => sanitizer}/_deprecate_quattroshapes.js (97%) rename test/unit/{sanitiser => sanitizer}/_flag_bool.js (97%) rename test/unit/{sanitiser => sanitizer}/_geo_common.js (99%) rename test/unit/{sanitiser => sanitizer}/_geo_reverse.js (98%) rename test/unit/{sanitiser => sanitizer}/_groups.js (97%) rename test/unit/{sanitiser => sanitizer}/_ids.js (99%) rename test/unit/{sanitiser => sanitizer}/_layers.js (98%) rename test/unit/{sanitiser => sanitizer}/_single_scalar_parameters.js (96%) rename test/unit/{sanitiser => sanitizer}/_size.js (97%) rename test/unit/{sanitiser => sanitizer}/_sources.js (98%) rename test/unit/{sanitiser => sanitizer}/_sources_and_layers.js (98%) rename test/unit/{sanitiser => sanitizer}/_text.js (85%) rename test/unit/{sanitiser => sanitizer}/_text_addressit.js (99%) rename test/unit/{sanitiser => sanitizer}/_tokenizer.js (92%) rename test/unit/{sanitiser => sanitizer}/_truthy.js (94%) rename test/unit/{sanitiser => sanitizer}/autocomplete.js (69%) rename test/unit/{sanitiser => sanitizer}/nearby.js (89%) rename test/unit/{sanitiser => sanitizer}/place.js (94%) rename test/unit/{sanitiser => sanitizer}/reverse.js (96%) rename test/unit/{sanitiser => sanitizer}/sanitizeAll.js (98%) rename test/unit/{sanitiser => sanitizer}/search.js (61%) rename test/unit/{sanitiser => sanitizer}/search_fallback.js (53%) rename test/unit/{sanitiser => sanitizer}/wrap.js (99%) diff --git a/routes/v1.js b/routes/v1.js index 362ed2cd..4e867766 100644 --- a/routes/v1.js +++ b/routes/v1.js @@ -2,14 +2,14 @@ var express = require('express'); var Router = require('express').Router; var reverseQuery = require('../query/reverse'); -/** ----------------------- sanitisers ----------------------- **/ -var sanitisers = { - autocomplete: require('../sanitiser/autocomplete'), - place: require('../sanitiser/place'), - search: require('../sanitiser/search'), - search_fallback: require('../sanitiser/search_fallback'), - reverse: require('../sanitiser/reverse'), - nearby: require('../sanitiser/nearby') +/** ----------------------- sanitizers ----------------------- **/ +var sanitizers = { + autocomplete: require('../sanitizer/autocomplete'), + place: require('../sanitizer/place'), + search: require('../sanitizer/search'), + search_fallback: require('../sanitizer/search_fallback'), + reverse: require('../sanitizer/reverse'), + nearby: require('../sanitizer/nearby') }; /** ----------------------- middleware ------------------------ **/ @@ -69,13 +69,13 @@ function addRoutes(app, peliasConfig) { controllers.mdToHTML(peliasConfig, './public/attribution.md') ]), search: createRouter([ - sanitisers.search.middleware, + sanitizers.search.middleware, middleware.calcSize(), // 2nd parameter is `backend` which gets initialized internally // 3rd parameter is which query module to use, use fallback/geodisambiguation // first, then use original search strategy if first query didn't return anything controllers.search(peliasConfig, undefined, queries.libpostal), - sanitisers.search_fallback.middleware, + sanitizers.search_fallback.middleware, controllers.search(peliasConfig, undefined, queries.fallback_to_old_prod), postProc.trimByGranularity(), postProc.distances('focus.point.'), @@ -91,7 +91,7 @@ function addRoutes(app, peliasConfig) { postProc.sendJSON ]), autocomplete: createRouter([ - sanitisers.autocomplete.middleware, + sanitizers.autocomplete.middleware, controllers.search(peliasConfig, null, require('../query/autocomplete')), postProc.distances('focus.point.'), postProc.confidenceScores(peliasConfig), @@ -105,7 +105,7 @@ function addRoutes(app, peliasConfig) { postProc.sendJSON ]), reverse: createRouter([ - sanitisers.reverse.middleware, + sanitizers.reverse.middleware, middleware.calcSize(), controllers.search(peliasConfig, undefined, reverseQuery), postProc.distances('point.'), @@ -122,7 +122,7 @@ function addRoutes(app, peliasConfig) { postProc.sendJSON ]), nearby: createRouter([ - sanitisers.nearby.middleware, + sanitizers.nearby.middleware, middleware.calcSize(), controllers.search(peliasConfig, undefined, reverseQuery), postProc.distances('point.'), @@ -139,7 +139,7 @@ function addRoutes(app, peliasConfig) { postProc.sendJSON ]), place: createRouter([ - sanitisers.place.middleware, + sanitizers.place.middleware, controllers.place(peliasConfig), postProc.accuracy(), postProc.localNamingConventions(), diff --git a/sanitiser/autocomplete.js b/sanitiser/autocomplete.js deleted file mode 100644 index 900edba2..00000000 --- a/sanitiser/autocomplete.js +++ /dev/null @@ -1,34 +0,0 @@ -var type_mapping = require('../helper/type_mapping'); - -var sanitizeAll = require('../sanitiser/sanitizeAll'), - sanitizers = { - singleScalarParameters: require('../sanitiser/_single_scalar_parameters'), - text: require('../sanitiser/_text_addressit'), - tokenizer: require('../sanitiser/_tokenizer'), - size: require('../sanitiser/_size')(10, 10, 10), - layers: require('../sanitiser/_targets')('layers', type_mapping.layer_mapping), - sources: require('../sanitiser/_targets')('sources', type_mapping.source_mapping), - // depends on the layers and sources sanitisers, must be run after them - sources_and_layers: require('../sanitiser/_sources_and_layers'), - private: require('../sanitiser/_flag_bool')('private', false), - geo_autocomplete: require('../sanitiser/_geo_autocomplete'), - boundary_country: require('../sanitiser/_boundary_country'), - categories: require('../sanitiser/_categories') - }; - -var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; - -// export sanitize for testing -module.exports.sanitize = sanitize; -module.exports.sanitiser_list = sanitizers; - -// middleware -module.exports.middleware = function( req, res, next ){ - sanitize( req, function( err, clean ){ - if( err ){ - res.status(400); // 400 Bad Request - return next(err); - } - next(); - }); -}; diff --git a/sanitiser/reverse.js b/sanitiser/reverse.js deleted file mode 100644 index b994455a..00000000 --- a/sanitiser/reverse.js +++ /dev/null @@ -1,28 +0,0 @@ - -var type_mapping = require('../helper/type_mapping'); -var sanitizeAll = require('../sanitiser/sanitizeAll'), - sanitizers = { - quattroshapes_deprecation: require('../sanitiser/_deprecate_quattroshapes'), - singleScalarParameters: require('../sanitiser/_single_scalar_parameters'), - layers: require('../sanitiser/_targets')('layers', type_mapping.layer_mapping), - sources: require('../sanitiser/_targets')('sources', type_mapping.source_mapping), - // depends on the layers and sources sanitisers, must be run after them - sources_and_layers: require('../sanitiser/_sources_and_layers'), - size: require('../sanitiser/_size')(/* use defaults*/), - private: require('../sanitiser/_flag_bool')('private', false), - geo_reverse: require('../sanitiser/_geo_reverse'), - boundary_country: require('../sanitiser/_boundary_country') - }; - -var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; - -// export sanitize for testing -module.exports.sanitize = sanitize; -module.exports.sanitiser_list = sanitizers; - -// middleware -module.exports.middleware = function( req, res, next ){ - sanitize( req, function( err, clean ){ - next(); - }); -}; diff --git a/sanitiser/search.js b/sanitiser/search.js deleted file mode 100644 index 130de40f..00000000 --- a/sanitiser/search.js +++ /dev/null @@ -1,26 +0,0 @@ -var type_mapping = require('../helper/type_mapping'); - -var sanitizeAll = require('../sanitiser/sanitizeAll'), - sanitizers = { - quattroshapes_deprecation: require('../sanitiser/_deprecate_quattroshapes'), - singleScalarParameters: require('../sanitiser/_single_scalar_parameters'), - text: require('../sanitiser/_text'), - size: require('../sanitiser/_size')(/* use defaults*/), - layers: require('../sanitiser/_targets')('layers', type_mapping.layer_mapping), - sources: require('../sanitiser/_targets')('sources', type_mapping.source_mapping), - // depends on the layers and sources sanitisers, must be run after them - sources_and_layers: require('../sanitiser/_sources_and_layers'), - private: require('../sanitiser/_flag_bool')('private', false), - geo_search: require('../sanitiser/_geo_search'), - boundary_country: require('../sanitiser/_boundary_country'), - categories: require('../sanitiser/_categories') - }; - -var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; - -// middleware -module.exports.middleware = function( req, res, next ){ - sanitize( req, function( err, clean ){ - next(); - }); -}; diff --git a/sanitiser/_boundary_country.js b/sanitizer/_boundary_country.js similarity index 100% rename from sanitiser/_boundary_country.js rename to sanitizer/_boundary_country.js diff --git a/sanitiser/_categories.js b/sanitizer/_categories.js similarity index 100% rename from sanitiser/_categories.js rename to sanitizer/_categories.js diff --git a/sanitiser/_deprecate_quattroshapes.js b/sanitizer/_deprecate_quattroshapes.js similarity index 100% rename from sanitiser/_deprecate_quattroshapes.js rename to sanitizer/_deprecate_quattroshapes.js diff --git a/sanitiser/_details.js b/sanitizer/_details.js similarity index 100% rename from sanitiser/_details.js rename to sanitizer/_details.js diff --git a/sanitiser/_flag_bool.js b/sanitizer/_flag_bool.js similarity index 100% rename from sanitiser/_flag_bool.js rename to sanitizer/_flag_bool.js diff --git a/sanitiser/_geo_autocomplete.js b/sanitizer/_geo_autocomplete.js similarity index 100% rename from sanitiser/_geo_autocomplete.js rename to sanitizer/_geo_autocomplete.js diff --git a/sanitiser/_geo_common.js b/sanitizer/_geo_common.js similarity index 98% rename from sanitiser/_geo_common.js rename to sanitizer/_geo_common.js index 1992a50d..d7620b08 100644 --- a/sanitiser/_geo_common.js +++ b/sanitizer/_geo_common.js @@ -1,5 +1,5 @@ /** - * helper sanitiser methods for geo parameters + * helper sanitizer methods for geo parameters */ var groups = require('./_groups'), util = require('util'), diff --git a/sanitiser/_geo_reverse.js b/sanitizer/_geo_reverse.js similarity index 100% rename from sanitiser/_geo_reverse.js rename to sanitizer/_geo_reverse.js diff --git a/sanitiser/_geo_search.js b/sanitizer/_geo_search.js similarity index 100% rename from sanitiser/_geo_search.js rename to sanitizer/_geo_search.js diff --git a/sanitiser/_groups.js b/sanitizer/_groups.js similarity index 100% rename from sanitiser/_groups.js rename to sanitizer/_groups.js diff --git a/sanitiser/_ids.js b/sanitizer/_ids.js similarity index 100% rename from sanitiser/_ids.js rename to sanitizer/_ids.js diff --git a/sanitiser/_single_scalar_parameters.js b/sanitizer/_single_scalar_parameters.js similarity index 100% rename from sanitiser/_single_scalar_parameters.js rename to sanitizer/_single_scalar_parameters.js diff --git a/sanitiser/_size.js b/sanitizer/_size.js similarity index 100% rename from sanitiser/_size.js rename to sanitizer/_size.js diff --git a/sanitiser/_sources_and_layers.js b/sanitizer/_sources_and_layers.js similarity index 89% rename from sanitiser/_sources_and_layers.js rename to sanitizer/_sources_and_layers.js index 448a7af1..fa0325b2 100644 --- a/sanitiser/_sources_and_layers.js +++ b/sanitizer/_sources_and_layers.js @@ -2,8 +2,8 @@ var _ = require( 'lodash' ); var type_mapping = require( '../helper/type_mapping' ); /* - * This sanitiser depends on clean.layers and clean.sources - * so it has to be run after those sanitisers have been run + * This sanitizer depends on clean.layers and clean.sources + * so it has to be run after those sanitizers have been run */ function sanitize( raw, clean ){ var messages = { errors: [], warnings: [] }; diff --git a/sanitiser/_targets.js b/sanitizer/_targets.js similarity index 100% rename from sanitiser/_targets.js rename to sanitizer/_targets.js diff --git a/sanitiser/_text.js b/sanitizer/_text.js similarity index 100% rename from sanitiser/_text.js rename to sanitizer/_text.js diff --git a/sanitiser/_text_addressit.js b/sanitizer/_text_addressit.js similarity index 100% rename from sanitiser/_text_addressit.js rename to sanitizer/_text_addressit.js diff --git a/sanitiser/_tokenizer.js b/sanitizer/_tokenizer.js similarity index 100% rename from sanitiser/_tokenizer.js rename to sanitizer/_tokenizer.js diff --git a/sanitizer/autocomplete.js b/sanitizer/autocomplete.js new file mode 100644 index 00000000..86f85447 --- /dev/null +++ b/sanitizer/autocomplete.js @@ -0,0 +1,34 @@ +var type_mapping = require('../helper/type_mapping'); + +var sanitizeAll = require('../sanitizer/sanitizeAll'), + sanitizers = { + singleScalarParameters: require('../sanitizer/_single_scalar_parameters'), + text: require('../sanitizer/_text_addressit'), + tokenizer: require('../sanitizer/_tokenizer'), + size: require('../sanitizer/_size')(10, 10, 10), + layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping), + sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping), + // depends on the layers and sources sanitizers, must be run after them + sources_and_layers: require('../sanitizer/_sources_and_layers'), + private: require('../sanitizer/_flag_bool')('private', false), + geo_autocomplete: require('../sanitizer/_geo_autocomplete'), + boundary_country: require('../sanitizer/_boundary_country'), + categories: require('../sanitizer/_categories') + }; + +var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; + +// export sanitize for testing +module.exports.sanitize = sanitize; +module.exports.sanitizer_list = sanitizers; + +// middleware +module.exports.middleware = function( req, res, next ){ + sanitize( req, function( err, clean ){ + if( err ){ + res.status(400); // 400 Bad Request + return next(err); + } + next(); + }); +}; diff --git a/sanitiser/nearby.js b/sanitizer/nearby.js similarity index 65% rename from sanitiser/nearby.js rename to sanitizer/nearby.js index 109c1ef0..d518b997 100644 --- a/sanitiser/nearby.js +++ b/sanitizer/nearby.js @@ -1,17 +1,17 @@ var _ = require('lodash'); -var sanitizeAll = require('../sanitiser/sanitizeAll'); -var reverseSanitizers = require('./reverse').sanitiser_list; +var sanitizeAll = require('../sanitizer/sanitizeAll'); +var reverseSanitizers = require('./reverse').sanitizer_list; // add categories to the sanitizer list var sanitizers = _.merge({}, reverseSanitizers, { - categories: require('../sanitiser/_categories') + categories: require('../sanitizer/_categories') }); var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; // export sanitize for testing module.exports.sanitize = sanitize; -module.exports.sanitiser_list = sanitizers; +module.exports.sanitizer_list = sanitizers; // middleware module.exports.middleware = function( req, res, next ){ diff --git a/sanitiser/place.js b/sanitizer/place.js similarity index 54% rename from sanitiser/place.js rename to sanitizer/place.js index 74c80c6b..3a6d4408 100644 --- a/sanitiser/place.js +++ b/sanitizer/place.js @@ -1,16 +1,16 @@ -var sanitizeAll = require('../sanitiser/sanitizeAll'), +var sanitizeAll = require('../sanitizer/sanitizeAll'), sanitizers = { - singleScalarParameters: require('../sanitiser/_single_scalar_parameters'), - ids: require('../sanitiser/_ids'), - private: require('../sanitiser/_flag_bool')('private', false) + singleScalarParameters: require('../sanitizer/_single_scalar_parameters'), + ids: require('../sanitizer/_ids'), + private: require('../sanitizer/_flag_bool')('private', false) }; var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; // export sanitize for testing module.exports.sanitize = sanitize; -module.exports.sanitiser_list = sanitizers; +module.exports.sanitizer_list = sanitizers; // middleware module.exports.middleware = function( req, res, next ){ diff --git a/sanitizer/reverse.js b/sanitizer/reverse.js new file mode 100644 index 00000000..90795a19 --- /dev/null +++ b/sanitizer/reverse.js @@ -0,0 +1,28 @@ + +var type_mapping = require('../helper/type_mapping'); +var sanitizeAll = require('../sanitizer/sanitizeAll'), + sanitizers = { + quattroshapes_deprecation: require('../sanitizer/_deprecate_quattroshapes'), + singleScalarParameters: require('../sanitizer/_single_scalar_parameters'), + layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping), + sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping), + // depends on the layers and sources sanitizers, must be run after them + sources_and_layers: require('../sanitizer/_sources_and_layers'), + size: require('../sanitizer/_size')(/* use defaults*/), + private: require('../sanitizer/_flag_bool')('private', false), + geo_reverse: require('../sanitizer/_geo_reverse'), + boundary_country: require('../sanitizer/_boundary_country') + }; + +var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; + +// export sanitize for testing +module.exports.sanitize = sanitize; +module.exports.sanitizer_list = sanitizers; + +// middleware +module.exports.middleware = function( req, res, next ){ + sanitize( req, function( err, clean ){ + next(); + }); +}; diff --git a/sanitiser/sanitizeAll.js b/sanitizer/sanitizeAll.js similarity index 100% rename from sanitiser/sanitizeAll.js rename to sanitizer/sanitizeAll.js diff --git a/sanitizer/search.js b/sanitizer/search.js new file mode 100644 index 00000000..53a6b57c --- /dev/null +++ b/sanitizer/search.js @@ -0,0 +1,26 @@ +var type_mapping = require('../helper/type_mapping'); + +var sanitizeAll = require('../sanitizer/sanitizeAll'), + sanitizers = { + quattroshapes_deprecation: require('../sanitizer/_deprecate_quattroshapes'), + singleScalarParameters: require('../sanitizer/_single_scalar_parameters'), + text: require('../sanitizer/_text'), + size: require('../sanitizer/_size')(/* use defaults*/), + layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping), + sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping), + // depends on the layers and sources sanitizers, must be run after them + sources_and_layers: require('../sanitizer/_sources_and_layers'), + private: require('../sanitizer/_flag_bool')('private', false), + geo_search: require('../sanitizer/_geo_search'), + boundary_country: require('../sanitizer/_boundary_country'), + categories: require('../sanitizer/_categories') + }; + +var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; + +// middleware +module.exports.middleware = function( req, res, next ){ + sanitize( req, function( err, clean ){ + next(); + }); +}; diff --git a/sanitiser/search_fallback.js b/sanitizer/search_fallback.js similarity index 89% rename from sanitiser/search_fallback.js rename to sanitizer/search_fallback.js index 1782dbdb..991f1fb0 100644 --- a/sanitiser/search_fallback.js +++ b/sanitizer/search_fallback.js @@ -1,6 +1,6 @@ -var sanitizeAll = require('../sanitiser/sanitizeAll'), +var sanitizeAll = require('../sanitizer/sanitizeAll'), sanitizers = { - text: require('../sanitiser/_text_addressit') + text: require('../sanitizer/_text_addressit') }; var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; diff --git a/sanitiser/wrap.js b/sanitizer/wrap.js similarity index 100% rename from sanitiser/wrap.js rename to sanitizer/wrap.js diff --git a/test/unit/run.js b/test/unit/run.js index be804d97..043bb131 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -44,31 +44,31 @@ var tests = [ require('./query/search'), require('./query/search_original'), require('./query/text_parser'), - require('./sanitiser/_boundary_country'), - require('./sanitiser/_flag_bool'), - require('./sanitiser/_geo_common'), - require('./sanitiser/_geo_reverse'), - require('./sanitiser/_groups'), - require('./sanitiser/_ids'), - require('./sanitiser/_layers'), - require('./sanitiser/_single_scalar_parameters'), - require('./sanitiser/_size'), - require('./sanitiser/_sources'), - require('./sanitiser/_sources_and_layers'), - require('./sanitiser/_text'), - require('./sanitiser/_text_addressit'), - require('./sanitiser/_tokenizer'), - require('./sanitiser/_deprecate_quattroshapes'), - require('./sanitiser/_categories'), - require('./sanitiser/nearby'), + require('./sanitizer/_boundary_country'), + require('./sanitizer/_flag_bool'), + require('./sanitizer/_geo_common'), + require('./sanitizer/_geo_reverse'), + require('./sanitizer/_groups'), + require('./sanitizer/_ids'), + require('./sanitizer/_layers'), + require('./sanitizer/_single_scalar_parameters'), + require('./sanitizer/_size'), + require('./sanitizer/_sources'), + require('./sanitizer/_sources_and_layers'), + require('./sanitizer/_text'), + require('./sanitizer/_text_addressit'), + require('./sanitizer/_tokenizer'), + require('./sanitizer/_deprecate_quattroshapes'), + require('./sanitizer/_categories'), + require('./sanitizer/nearby'), require('./src/backend'), - require('./sanitiser/autocomplete'), - require('./sanitiser/place'), - require('./sanitiser/reverse'), - require('./sanitiser/sanitizeAll'), - require('./sanitiser/search'), - require('./sanitiser/search_fallback'), - require('./sanitiser/wrap'), + require('./sanitizer/autocomplete'), + require('./sanitizer/place'), + require('./sanitizer/reverse'), + require('./sanitizer/sanitizeAll'), + require('./sanitizer/search'), + require('./sanitizer/search_fallback'), + require('./sanitizer/wrap'), require('./service/mget'), require('./service/search') ]; diff --git a/test/unit/sanitiser/_boundary_country.js b/test/unit/sanitizer/_boundary_country.js similarity index 98% rename from test/unit/sanitiser/_boundary_country.js rename to test/unit/sanitizer/_boundary_country.js index db6a0e20..9411acdf 100644 --- a/test/unit/sanitiser/_boundary_country.js +++ b/test/unit/sanitizer/_boundary_country.js @@ -1,4 +1,4 @@ -var sanitize = require('../../../sanitiser/_boundary_country'); +var sanitize = require('../../../sanitizer/_boundary_country'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/_categories.js b/test/unit/sanitizer/_categories.js similarity index 98% rename from test/unit/sanitiser/_categories.js rename to test/unit/sanitizer/_categories.js index 743423a9..64e9555f 100644 --- a/test/unit/sanitiser/_categories.js +++ b/test/unit/sanitizer/_categories.js @@ -1,4 +1,4 @@ -var sanitize = require( '../../../sanitiser/_categories'); +var sanitize = require( '../../../sanitizer/_categories'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/_deprecate_quattroshapes.js b/test/unit/sanitizer/_deprecate_quattroshapes.js similarity index 97% rename from test/unit/sanitiser/_deprecate_quattroshapes.js rename to test/unit/sanitizer/_deprecate_quattroshapes.js index 9a4ab53d..61b581aa 100644 --- a/test/unit/sanitiser/_deprecate_quattroshapes.js +++ b/test/unit/sanitizer/_deprecate_quattroshapes.js @@ -1,4 +1,4 @@ -var sanitize = require('../../../sanitiser/_deprecate_quattroshapes'); +var sanitize = require('../../../sanitizer/_deprecate_quattroshapes'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/_flag_bool.js b/test/unit/sanitizer/_flag_bool.js similarity index 97% rename from test/unit/sanitiser/_flag_bool.js rename to test/unit/sanitizer/_flag_bool.js index 9e4252c9..55ecdc94 100644 --- a/test/unit/sanitiser/_flag_bool.js +++ b/test/unit/sanitizer/_flag_bool.js @@ -1,4 +1,4 @@ -var sanitizer = require('../../../sanitiser/_flag_bool'); +var sanitizer = require('../../../sanitizer/_flag_bool'); var sanitize = sanitizer('dirty_param', true); module.exports.tests = {}; diff --git a/test/unit/sanitiser/_geo_common.js b/test/unit/sanitizer/_geo_common.js similarity index 99% rename from test/unit/sanitiser/_geo_common.js rename to test/unit/sanitizer/_geo_common.js index a7bff983..bdb58078 100644 --- a/test/unit/sanitiser/_geo_common.js +++ b/test/unit/sanitizer/_geo_common.js @@ -1,4 +1,4 @@ -var sanitize = require('../../../sanitiser/_geo_common'); +var sanitize = require('../../../sanitizer/_geo_common'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/_geo_reverse.js b/test/unit/sanitizer/_geo_reverse.js similarity index 98% rename from test/unit/sanitiser/_geo_reverse.js rename to test/unit/sanitizer/_geo_reverse.js index 107630a8..d0b99ca7 100644 --- a/test/unit/sanitiser/_geo_reverse.js +++ b/test/unit/sanitizer/_geo_reverse.js @@ -1,4 +1,4 @@ -var sanitize = require('../../../sanitiser/_geo_reverse'); +var sanitize = require('../../../sanitizer/_geo_reverse'); var defaults = require('../../../query/reverse_defaults'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/_groups.js b/test/unit/sanitizer/_groups.js similarity index 97% rename from test/unit/sanitiser/_groups.js rename to test/unit/sanitizer/_groups.js index 63b86ea7..a184f1ae 100644 --- a/test/unit/sanitiser/_groups.js +++ b/test/unit/sanitizer/_groups.js @@ -1,4 +1,4 @@ -var groups = require('../../../sanitiser/_groups'); +var groups = require('../../../sanitizer/_groups'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/_ids.js b/test/unit/sanitizer/_ids.js similarity index 99% rename from test/unit/sanitiser/_ids.js rename to test/unit/sanitizer/_ids.js index b6b30a5a..e1dfb680 100644 --- a/test/unit/sanitiser/_ids.js +++ b/test/unit/sanitizer/_ids.js @@ -1,4 +1,4 @@ -var sanitize = require('../../../sanitiser/_ids'); +var sanitize = require('../../../sanitizer/_ids'); var delimiter = ':'; var type_mapping = require('../../../helper/type_mapping'); diff --git a/test/unit/sanitiser/_layers.js b/test/unit/sanitizer/_layers.js similarity index 98% rename from test/unit/sanitiser/_layers.js rename to test/unit/sanitizer/_layers.js index a1fde0f4..5792e947 100644 --- a/test/unit/sanitiser/_layers.js +++ b/test/unit/sanitizer/_layers.js @@ -1,6 +1,6 @@ var type_mapping = require('../../../helper/type_mapping'); -var sanitize = require('../../../sanitiser/_targets')('layers', type_mapping.layer_mapping); +var sanitize = require('../../../sanitizer/_targets')('layers', type_mapping.layer_mapping); module.exports.tests = {}; diff --git a/test/unit/sanitiser/_single_scalar_parameters.js b/test/unit/sanitizer/_single_scalar_parameters.js similarity index 96% rename from test/unit/sanitiser/_single_scalar_parameters.js rename to test/unit/sanitizer/_single_scalar_parameters.js index 4b1fc9d0..4337d6d1 100644 --- a/test/unit/sanitiser/_single_scalar_parameters.js +++ b/test/unit/sanitizer/_single_scalar_parameters.js @@ -1,4 +1,4 @@ -var sanitize = require('../../../sanitiser/_single_scalar_parameters'); +var sanitize = require('../../../sanitizer/_single_scalar_parameters'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/_size.js b/test/unit/sanitizer/_size.js similarity index 97% rename from test/unit/sanitiser/_size.js rename to test/unit/sanitizer/_size.js index 67c8bd84..6553685d 100644 --- a/test/unit/sanitiser/_size.js +++ b/test/unit/sanitizer/_size.js @@ -1,4 +1,4 @@ -var sanitize = require('../../../sanitiser/_size'); +var sanitize = require('../../../sanitizer/_size'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/_sources.js b/test/unit/sanitizer/_sources.js similarity index 98% rename from test/unit/sanitiser/_sources.js rename to test/unit/sanitizer/_sources.js index b0daffef..e8eb8ef5 100644 --- a/test/unit/sanitiser/_sources.js +++ b/test/unit/sanitizer/_sources.js @@ -1,5 +1,5 @@ var type_mapping = require('../../../helper/type_mapping'); -var sanitize = require( '../../../sanitiser/_targets' )('sources', type_mapping.source_mapping); +var sanitize = require( '../../../sanitizer/_targets' )('sources', type_mapping.source_mapping); var success_messages = { error: false }; diff --git a/test/unit/sanitiser/_sources_and_layers.js b/test/unit/sanitizer/_sources_and_layers.js similarity index 98% rename from test/unit/sanitiser/_sources_and_layers.js rename to test/unit/sanitizer/_sources_and_layers.js index 5b8bf3a2..f506c1f9 100644 --- a/test/unit/sanitiser/_sources_and_layers.js +++ b/test/unit/sanitizer/_sources_and_layers.js @@ -1,4 +1,4 @@ -var sanitize = require('../../../sanitiser/_sources_and_layers'); +var sanitize = require('../../../sanitizer/_sources_and_layers'); var type_mapping = require('../../../helper/type_mapping'); diff --git a/test/unit/sanitiser/_text.js b/test/unit/sanitizer/_text.js similarity index 85% rename from test/unit/sanitiser/_text.js rename to test/unit/sanitizer/_text.js index 82dfb5e0..c29f0a1d 100644 --- a/test/unit/sanitiser/_text.js +++ b/test/unit/sanitizer/_text.js @@ -10,7 +10,7 @@ module.exports.tests.text_parser = function(test, common) { key2: 'value 2' }; - var sanitiser = proxyquire('../../../sanitiser/_text', { + var sanitizer = proxyquire('../../../sanitizer/_text', { 'pelias-text-analyzer': { parse: function(query) { return mock_analyzer_response; } @@ -27,7 +27,7 @@ module.exports.tests.text_parser = function(test, common) { parsed_text: mock_analyzer_response }; - var messages = sanitiser(raw, clean); + var messages = sanitizer(raw, clean); t.deepEquals(clean, expected_clean); t.deepEquals(messages.errors, [], 'no errors'); @@ -37,7 +37,7 @@ module.exports.tests.text_parser = function(test, common) { }); test('empty raw.text should add error message', function(t) { - var sanitiser = proxyquire('../../../sanitiser/_text', { + var sanitizer = proxyquire('../../../sanitizer/_text', { 'pelias-text-analyzer': { parse: function(query) { throw new Error('analyzer should not have been called'); } @@ -52,7 +52,7 @@ module.exports.tests.text_parser = function(test, common) { var expected_clean = { }; - var messages = sanitiser(raw, clean); + var messages = sanitizer(raw, clean); t.deepEquals(clean, expected_clean); t.deepEquals(messages.errors, ['invalid param \'text\': text length, must be >0'], 'no errors'); @@ -62,7 +62,7 @@ module.exports.tests.text_parser = function(test, common) { }); test('undefined raw.text should add error message', function(t) { - var sanitiser = proxyquire('../../../sanitiser/_text', { + var sanitizer = proxyquire('../../../sanitizer/_text', { 'pelias-text-analyzer': { parse: function(query) { throw new Error('analyzer should not have been called'); } @@ -77,7 +77,7 @@ module.exports.tests.text_parser = function(test, common) { var expected_clean = { }; - var messages = sanitiser(raw, clean); + var messages = sanitizer(raw, clean); t.deepEquals(clean, expected_clean); t.deepEquals(messages.errors, ['invalid param \'text\': text length, must be >0'], 'no errors'); @@ -87,7 +87,7 @@ module.exports.tests.text_parser = function(test, common) { }); test('text_analyzer.parse returning undefined should not overwrite clean.parsed_text', function(t) { - var sanitiser = proxyquire('../../../sanitiser/_text', { + var sanitizer = proxyquire('../../../sanitizer/_text', { 'pelias-text-analyzer': { parse: function(query) { return undefined; } @@ -105,7 +105,7 @@ module.exports.tests.text_parser = function(test, common) { parsed_text: 'original clean.parsed_text' }; - var messages = sanitiser(raw, clean); + var messages = sanitizer(raw, clean); t.deepEquals(clean, expected_clean); t.deepEquals(messages.errors, [], 'no errors'); @@ -115,7 +115,7 @@ module.exports.tests.text_parser = function(test, common) { }); test('text_analyzer.parse returning null should not overwrite clean.parsed_text', function(t) { - var sanitiser = proxyquire('../../../sanitiser/_text', { + var sanitizer = proxyquire('../../../sanitizer/_text', { 'pelias-text-analyzer': { parse: function(query) { return null; } @@ -133,7 +133,7 @@ module.exports.tests.text_parser = function(test, common) { parsed_text: 'original clean.parsed_text' }; - var messages = sanitiser(raw, clean); + var messages = sanitizer(raw, clean); t.deepEquals(clean, expected_clean); t.deepEquals(messages.errors, [], 'no errors'); @@ -146,7 +146,7 @@ module.exports.tests.text_parser = function(test, common) { module.exports.all = function (tape, common) { function test(name, testFunction) { - return tape('SANITISER _text: ' + name, testFunction); + return tape('sanitizeR _text: ' + name, testFunction); } for( var testCase in module.exports.tests ){ diff --git a/test/unit/sanitiser/_text_addressit.js b/test/unit/sanitizer/_text_addressit.js similarity index 99% rename from test/unit/sanitiser/_text_addressit.js rename to test/unit/sanitizer/_text_addressit.js index 91e1665a..87fa3382 100644 --- a/test/unit/sanitiser/_text_addressit.js +++ b/test/unit/sanitizer/_text_addressit.js @@ -1,4 +1,4 @@ -var sanitiser = require('../../../sanitiser/_text_addressit'); +var sanitiser = require('../../../sanitizer/_text_addressit'); var type_mapping = require('../../../helper/type_mapping'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/_tokenizer.js b/test/unit/sanitizer/_tokenizer.js similarity index 92% rename from test/unit/sanitiser/_tokenizer.js rename to test/unit/sanitizer/_tokenizer.js index 58d9cca8..c5208ffe 100644 --- a/test/unit/sanitiser/_tokenizer.js +++ b/test/unit/sanitizer/_tokenizer.js @@ -1,4 +1,4 @@ -var sanitiser = require('../../../sanitiser/_tokenizer'); +var sanitizer = require('../../../sanitizer/_tokenizer'); module.exports.tests = {}; @@ -6,7 +6,7 @@ module.exports.tests.sanity_checks = function(test, common) { test('clean.text not set', function(t) { var clean = {}; // clean.text not set - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // no tokens produced t.deepEquals(clean.tokens, [], 'no tokens'); @@ -22,7 +22,7 @@ module.exports.tests.sanity_checks = function(test, common) { test('clean.text not a string', function(t) { var clean = { text: {} }; // clean.text not a string - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // no tokens produced t.deepEquals(clean.tokens, [], 'no tokens'); @@ -38,7 +38,7 @@ module.exports.tests.sanity_checks = function(test, common) { test('empty string', function(t) { var clean = { text: '' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // no tokens produced t.deepEquals(clean.tokens, [], 'no tokens'); @@ -54,7 +54,7 @@ module.exports.tests.sanity_checks = function(test, common) { test('clean.parsed_text set but clean.parsed_text.name invalid', function(t) { var clean = { parsed_text: { text: {} } }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // no tokens produced t.deepEquals(clean.tokens, [], 'no tokens'); @@ -70,7 +70,7 @@ module.exports.tests.sanity_checks = function(test, common) { test('favor clean.parsed_text.name over clean.text', function(t) { var clean = { parsed_text: { name: 'foo' }, text: 'bar' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // favor clean.parsed_text.name over clean.text t.deepEquals(clean.tokens, [ 'foo' ], 'use clean.parsed_text.name'); @@ -86,7 +86,7 @@ module.exports.tests.sanity_checks = function(test, common) { test('favor clean.parsed_text street data over clean.text', function(t) { var clean = { parsed_text: { number: '190', street: 'foo st' }, text: 'bar' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // favor clean.parsed_text.name over clean.text t.deepEquals(clean.tokens, [ '190', 'foo', 'st' ], 'use street name + number'); @@ -102,7 +102,7 @@ module.exports.tests.sanity_checks = function(test, common) { test('favor clean.parsed_text.name over clean.parsed_text street data', function(t) { var clean = { parsed_text: { number: '190', street: 'foo st', name: 'foo' }, text: 'bar' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // favor clean.parsed_text.name over all other variables t.deepEquals(clean.tokens, [ 'foo' ], 'use clean.parsed_text.name'); @@ -121,7 +121,7 @@ module.exports.tests.space_delimiter = function(test, common) { test('space delimiter - simple', function(t) { var clean = { text: '30 west 26th street new york' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // tokens produced t.deepEquals(clean.tokens, [ @@ -156,7 +156,7 @@ module.exports.tests.space_delimiter = function(test, common) { test('space delimiter - multiple spaces / other whitespace', function(t) { var clean = { text: ' 30 west \t26th \nstreet new york ' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // tokens produced t.deepEquals(clean.tokens, [ @@ -194,7 +194,7 @@ module.exports.tests.comma_delimiter = function(test, common) { test('comma delimiter - simple', function(t) { var clean = { text: '30 west 26th street, new york' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // tokens produced t.deepEquals(clean.tokens, [ @@ -229,7 +229,7 @@ module.exports.tests.comma_delimiter = function(test, common) { test('comma delimiter - multiple commas', function(t) { var clean = { text: ',30 west 26th street,,, new york,' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // tokens produced t.deepEquals(clean.tokens, [ @@ -267,7 +267,7 @@ module.exports.tests.forward_slash_delimiter = function(test, common) { test('forward slash delimiter - simple', function(t) { var clean = { text: 'Bedell Street/133rd Avenue' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // tokens produced t.deepEquals(clean.tokens, [ @@ -298,7 +298,7 @@ module.exports.tests.forward_slash_delimiter = function(test, common) { test('forward slash - multiple slashes', function(t) { var clean = { text: '/Bedell Street//133rd Avenue/' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // tokens produced t.deepEquals(clean.tokens, [ @@ -332,7 +332,7 @@ module.exports.tests.final_token_single_gram = function(test, common) { test('final token single gram - numeric', function(t) { var clean = { text: 'grolmanstrasse 1' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // tokens produced t.deepEquals(clean.tokens, [ @@ -359,7 +359,7 @@ module.exports.tests.final_token_single_gram = function(test, common) { test('final token single gram - non-numeric', function(t) { var clean = { text: 'grolmanstrasse a' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // tokens produced t.deepEquals(clean.tokens, [ @@ -389,7 +389,7 @@ module.exports.tests.back_slash_delimiter = function(test, common) { test('back slash delimiter - simple', function(t) { var clean = { text: 'Bedell Street\\133rd Avenue' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // tokens produced t.deepEquals(clean.tokens, [ @@ -408,7 +408,7 @@ module.exports.tests.back_slash_delimiter = function(test, common) { test('back slash - multiple slashes', function(t) { var clean = { text: '\\Bedell Street\\\\133rd Avenue\\' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // tokens produced t.deepEquals(clean.tokens, [ @@ -430,7 +430,7 @@ module.exports.tests.mixed_delimiter = function(test, common) { test('mixed delimiters', function(t) { var clean = { text: ',/Bedell Street\\, \n\t ,\\//133rd Avenue, /\n/' }; - var messages = sanitiser({}, clean); + var messages = sanitizer({}, clean); // tokens produced t.deepEquals(clean.tokens, [ @@ -450,7 +450,7 @@ module.exports.tests.mixed_delimiter = function(test, common) { module.exports.all = function (tape, common) { function test(name, testFunction) { - return tape('SANITISER _tokenizer: ' + name, testFunction); + return tape('sanitizeR _tokenizer: ' + name, testFunction); } for( var testCase in module.exports.tests ){ diff --git a/test/unit/sanitiser/_truthy.js b/test/unit/sanitizer/_truthy.js similarity index 94% rename from test/unit/sanitiser/_truthy.js rename to test/unit/sanitizer/_truthy.js index ea43dda1..932a840b 100644 --- a/test/unit/sanitiser/_truthy.js +++ b/test/unit/sanitizer/_truthy.js @@ -1,4 +1,4 @@ -var isTruthy = require('../../../sanitiser/_truthy'); +var isTruthy = require('../../../sanitizer/_truthy'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/autocomplete.js b/test/unit/sanitizer/autocomplete.js similarity index 69% rename from test/unit/sanitiser/autocomplete.js rename to test/unit/sanitizer/autocomplete.js index 289bf774..29db50ee 100644 --- a/test/unit/sanitiser/autocomplete.js +++ b/test/unit/sanitizer/autocomplete.js @@ -1,14 +1,14 @@ -var autocomplete = require('../../../sanitiser/autocomplete'); +var autocomplete = require('../../../sanitizer/autocomplete'); module.exports.tests = {}; -module.exports.tests.sanitisers = function(test, common) { - test('check sanitiser list', function (t) { +module.exports.tests.sanitizers = function(test, common) { + test('check sanitizer list', function (t) { var expected = [ 'singleScalarParameters', 'text', 'tokenizer', 'size', 'layers', 'sources', 'sources_and_layers', 'private', 'geo_autocomplete', 'boundary_country', 'categories' ]; - t.deepEqual(Object.keys(autocomplete.sanitiser_list), expected); + t.deepEqual(Object.keys(autocomplete.sanitizer_list), expected); t.end(); }); }; diff --git a/test/unit/sanitiser/nearby.js b/test/unit/sanitizer/nearby.js similarity index 89% rename from test/unit/sanitiser/nearby.js rename to test/unit/sanitizer/nearby.js index 1441b903..666944d0 100644 --- a/test/unit/sanitiser/nearby.js +++ b/test/unit/sanitizer/nearby.js @@ -1,5 +1,5 @@ -var nearby = require('../../../sanitiser/nearby'); +var nearby = require('../../../sanitizer/nearby'); var defaults = require('../../../query/reverse_defaults'); var sanitize = nearby.sanitize; var middleware = nearby.middleware; @@ -28,11 +28,11 @@ module.exports.tests.interface = function(test, common) { }); }; -module.exports.tests.sanitisers = function(test, common) { - test('check sanitiser list', function (t) { +module.exports.tests.sanitizers = function(test, common) { + test('check sanitizer list', function (t) { var expected = ['quattroshapes_deprecation', 'singleScalarParameters', 'layers', 'sources', 'sources_and_layers', 'size', 'private', 'geo_reverse', 'boundary_country', 'categories']; - t.deepEqual(Object.keys(nearby.sanitiser_list), expected); + t.deepEqual(Object.keys(nearby.sanitizer_list), expected); t.end(); }); }; diff --git a/test/unit/sanitiser/place.js b/test/unit/sanitizer/place.js similarity index 94% rename from test/unit/sanitiser/place.js rename to test/unit/sanitizer/place.js index dd9d1645..b7a4b6b8 100644 --- a/test/unit/sanitiser/place.js +++ b/test/unit/sanitizer/place.js @@ -1,4 +1,4 @@ -var place = require('../../../sanitiser/place'), +var place = require('../../../sanitizer/place'), sanitize = place.sanitize, middleware = place.middleware, defaultClean = { ids: [ { source: 'geonames', layer: 'venue', id: '123' } ], private: false }; @@ -19,10 +19,10 @@ module.exports.tests.interface = function(test, common) { }); }; -module.exports.tests.sanitisers = function(test, common) { - test('check sanitiser list', function (t) { +module.exports.tests.sanitizers = function(test, common) { + test('check sanitizer list', function (t) { var expected = ['singleScalarParameters', 'ids', 'private' ]; - t.deepEqual(Object.keys(place.sanitiser_list), expected); + t.deepEqual(Object.keys(place.sanitizer_list), expected); t.end(); }); }; diff --git a/test/unit/sanitiser/reverse.js b/test/unit/sanitizer/reverse.js similarity index 96% rename from test/unit/sanitiser/reverse.js rename to test/unit/sanitizer/reverse.js index 089e1aaf..96cec51a 100644 --- a/test/unit/sanitiser/reverse.js +++ b/test/unit/sanitizer/reverse.js @@ -1,7 +1,7 @@ // @todo: refactor this test, it's pretty messy, brittle and hard to follow -var reverse = require('../../../sanitiser/reverse'), +var reverse = require('../../../sanitizer/reverse'), sanitize = reverse.sanitize, middleware = reverse.middleware, defaults = require('../../../query/reverse_defaults'), @@ -34,11 +34,11 @@ module.exports.tests.interface = function(test, common) { }); }; -module.exports.tests.sanitisers = function(test, common) { - test('check sanitiser list', function (t) { +module.exports.tests.sanitizers = function(test, common) { + test('check sanitizer list', function (t) { var expected = ['quattroshapes_deprecation', 'singleScalarParameters', 'layers', 'sources', 'sources_and_layers', 'size', 'private', 'geo_reverse', 'boundary_country']; - t.deepEqual(Object.keys(reverse.sanitiser_list), expected); + t.deepEqual(Object.keys(reverse.sanitizer_list), expected); t.end(); }); }; diff --git a/test/unit/sanitiser/sanitizeAll.js b/test/unit/sanitizer/sanitizeAll.js similarity index 98% rename from test/unit/sanitiser/sanitizeAll.js rename to test/unit/sanitizer/sanitizeAll.js index 3d78e599..bcddba05 100644 --- a/test/unit/sanitiser/sanitizeAll.js +++ b/test/unit/sanitizer/sanitizeAll.js @@ -1,4 +1,4 @@ -var sanitizeAll = require('../../../sanitiser/sanitizeAll'); +var sanitizeAll = require('../../../sanitizer/sanitizeAll'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/search.js b/test/unit/sanitizer/search.js similarity index 61% rename from test/unit/sanitiser/search.js rename to test/unit/sanitizer/search.js index 3c5c684d..b656d943 100644 --- a/test/unit/sanitiser/search.js +++ b/test/unit/sanitizer/search.js @@ -3,28 +3,28 @@ var proxyquire = require('proxyquire').noCallThru(); module.exports.tests = {}; module.exports.tests.sanitize = function(test, common) { - test('verify that all sanitisers were called as expected', function(t) { - var called_sanitisers = []; + test('verify that all sanitizers were called as expected', function(t) { + var called_sanitizers = []; - // rather than re-verify the functionality of all the sanitisers, this test just verifies that they + // rather than re-verify the functionality of all the sanitizers, this test just verifies that they // were all called correctly - var search = proxyquire('../../../sanitiser/search', { - '../sanitiser/_deprecate_quattroshapes': function() { - called_sanitisers.push('_deprecate_quattroshapes'); + var search = proxyquire('../../../sanitizer/search', { + '../sanitizer/_deprecate_quattroshapes': function() { + called_sanitizers.push('_deprecate_quattroshapes'); return { errors: [], warnings: [] }; }, - '../sanitiser/_single_scalar_parameters': function() { - called_sanitisers.push('_single_scalar_parameters'); + '../sanitizer/_single_scalar_parameters': function() { + called_sanitizers.push('_single_scalar_parameters'); return { errors: [], warnings: [] }; }, - '../sanitiser/_text': function() { - called_sanitisers.push('_text'); + '../sanitizer/_text': function() { + called_sanitizers.push('_text'); return { errors: [], warnings: [] }; }, - '../sanitiser/_size': function() { + '../sanitizer/_size': function() { if (arguments.length === 0) { return function() { - called_sanitisers.push('_size'); + called_sanitizers.push('_size'); return { errors: [], warnings: [] }; }; @@ -33,10 +33,10 @@ module.exports.tests.sanitize = function(test, common) { } }, - '../sanitiser/_targets': function(type) { + '../sanitizer/_targets': function(type) { if (['layers', 'sources'].indexOf(type) !== -1) { return function() { - called_sanitisers.push('_targets/' + type); + called_sanitizers.push('_targets/' + type); return { errors: [], warnings: [] }; }; @@ -46,14 +46,14 @@ module.exports.tests.sanitize = function(test, common) { } }, - '../sanitiser/_sources_and_layers': function() { - called_sanitisers.push('_sources_and_layers'); + '../sanitizer/_sources_and_layers': function() { + called_sanitizers.push('_sources_and_layers'); return { errors: [], warnings: [] }; }, - '../sanitiser/_flag_bool': function() { + '../sanitizer/_flag_bool': function() { if (arguments[0] === 'private' && arguments[1] === false) { return function() { - called_sanitisers.push('_flag_bool'); + called_sanitizers.push('_flag_bool'); return { errors: [], warnings: [] }; }; @@ -63,21 +63,21 @@ module.exports.tests.sanitize = function(test, common) { } }, - '../sanitiser/_geo_search': function() { - called_sanitisers.push('_geo_search'); + '../sanitizer/_geo_search': function() { + called_sanitizers.push('_geo_search'); return { errors: [], warnings: [] }; }, - '../sanitiser/_boundary_country': function() { - called_sanitisers.push('_boundary_country'); + '../sanitizer/_boundary_country': function() { + called_sanitizers.push('_boundary_country'); return { errors: [], warnings: [] }; }, - '../sanitiser/_categories': function() { - called_sanitisers.push('_categories'); + '../sanitizer/_categories': function() { + called_sanitizers.push('_categories'); return { errors: [], warnings: [] }; }, }); - var expected_sanitisers = [ + var expected_sanitizers = [ '_deprecate_quattroshapes', '_single_scalar_parameters', '_text', @@ -95,7 +95,7 @@ module.exports.tests.sanitize = function(test, common) { var res = {}; search.middleware(req, res, function(){ - t.deepEquals(called_sanitisers, expected_sanitisers); + t.deepEquals(called_sanitizers, expected_sanitizers); t.end(); }); }); diff --git a/test/unit/sanitiser/search_fallback.js b/test/unit/sanitizer/search_fallback.js similarity index 53% rename from test/unit/sanitiser/search_fallback.js rename to test/unit/sanitizer/search_fallback.js index dd8fff2a..82bad1b0 100644 --- a/test/unit/sanitiser/search_fallback.js +++ b/test/unit/sanitizer/search_fallback.js @@ -3,44 +3,44 @@ var proxyquire = require('proxyquire').noCallThru(); module.exports.tests = {}; module.exports.tests.sanitize = function(test, common) { - test('verify that all sanitisers were called as expected when `res` is undefined', function(t) { - var called_sanitisers = []; + test('verify that all sanitizers were called as expected when `res` is undefined', function(t) { + var called_sanitizers = []; - // rather than re-verify the functionality of all the sanitisers, this test just verifies that they + // rather than re-verify the functionality of all the sanitizers, this test just verifies that they // were all called correctly - var search = proxyquire('../../../sanitiser/search_fallback', { - '../sanitiser/_text_addressit': function() { - called_sanitisers.push('_text_addressit'); + var search = proxyquire('../../../sanitizer/search_fallback', { + '../sanitizer/_text_addressit': function() { + called_sanitizers.push('_text_addressit'); return { errors: [], warnings: [] }; } }); - var expected_sanitisers = [ + var expected_sanitizers = [ '_text_addressit' ]; var req = {}; search.middleware(req, undefined, function(){ - t.deepEquals(called_sanitisers, expected_sanitisers); + t.deepEquals(called_sanitizers, expected_sanitizers); t.end(); }); }); - test('verify that all sanitisers were called as expected when `res` has no `data` property', function(t) { - var called_sanitisers = []; + test('verify that all sanitizers were called as expected when `res` has no `data` property', function(t) { + var called_sanitizers = []; - // rather than re-verify the functionality of all the sanitisers, this test just verifies that they + // rather than re-verify the functionality of all the sanitizers, this test just verifies that they // were all called correctly - var search = proxyquire('../../../sanitiser/search_fallback', { - '../sanitiser/_text_addressit': function() { - called_sanitisers.push('_text_addressit'); + var search = proxyquire('../../../sanitizer/search_fallback', { + '../sanitizer/_text_addressit': function() { + called_sanitizers.push('_text_addressit'); return { errors: [], warnings: [] }; } }); - var expected_sanitisers = [ + var expected_sanitizers = [ '_text_addressit' ]; @@ -48,25 +48,25 @@ module.exports.tests.sanitize = function(test, common) { var res = {}; search.middleware(req, res, function(){ - t.deepEquals(called_sanitisers, expected_sanitisers); + t.deepEquals(called_sanitizers, expected_sanitizers); t.end(); }); }); - test('verify that all sanitisers were called as expected when res.data is empty', function(t) { - var called_sanitisers = []; + test('verify that all sanitizers were called as expected when res.data is empty', function(t) { + var called_sanitizers = []; - // rather than re-verify the functionality of all the sanitisers, this test just verifies that they + // rather than re-verify the functionality of all the sanitizers, this test just verifies that they // were all called correctly - var search = proxyquire('../../../sanitiser/search_fallback', { - '../sanitiser/_text_addressit': function() { - called_sanitisers.push('_text_addressit'); + var search = proxyquire('../../../sanitizer/search_fallback', { + '../sanitizer/_text_addressit': function() { + called_sanitizers.push('_text_addressit'); return { errors: [], warnings: [] }; } }); - var expected_sanitisers = [ + var expected_sanitizers = [ '_text_addressit' ]; @@ -76,24 +76,24 @@ module.exports.tests.sanitize = function(test, common) { }; search.middleware(req, res, function(){ - t.deepEquals(called_sanitisers, expected_sanitisers); + t.deepEquals(called_sanitizers, expected_sanitizers); t.end(); }); }); - test('non-empty res.data should not call the _text_autocomplete sanitiser', function(t) { - var called_sanitisers = []; + test('non-empty res.data should not call the _text_autocomplete sanitizer', function(t) { + var called_sanitizers = []; - // rather than re-verify the functionality of all the sanitisers, this test just verifies that they + // rather than re-verify the functionality of all the sanitizers, this test just verifies that they // were all called correctly - var search = proxyquire('../../../sanitiser/search_fallback', { - '../sanitiser/_text_autocomplete': function() { - throw new Error('_text_autocomplete sanitiser should not have been called'); + var search = proxyquire('../../../sanitizer/search_fallback', { + '../sanitizer/_text_autocomplete': function() { + throw new Error('_text_autocomplete sanitizer should not have been called'); } }); - var expected_sanitisers = []; + var expected_sanitizers = []; var req = {}; var res = { @@ -101,7 +101,7 @@ module.exports.tests.sanitize = function(test, common) { }; search.middleware(req, res, function(){ - t.deepEquals(called_sanitisers, expected_sanitisers); + t.deepEquals(called_sanitizers, expected_sanitizers); t.end(); }); diff --git a/test/unit/sanitiser/wrap.js b/test/unit/sanitizer/wrap.js similarity index 99% rename from test/unit/sanitiser/wrap.js rename to test/unit/sanitizer/wrap.js index ea9a75a5..3339b51c 100644 --- a/test/unit/sanitiser/wrap.js +++ b/test/unit/sanitizer/wrap.js @@ -1,5 +1,5 @@ -var wrap = require('../../../sanitiser/wrap'); +var wrap = require('../../../sanitizer/wrap'); module.exports.tests = {};