Browse Source

Merge pull request #685 from pelias/master

Merge master into staging
pull/686/head
Julian Simioni 8 years ago committed by GitHub
parent
commit
70687cb12e
  1. 2
      query/search.js
  2. 28
      routes/v1.js
  3. 34
      sanitiser/autocomplete.js
  4. 28
      sanitiser/reverse.js
  5. 26
      sanitiser/search.js
  6. 0
      sanitizer/_boundary_country.js
  7. 0
      sanitizer/_categories.js
  8. 0
      sanitizer/_deprecate_quattroshapes.js
  9. 0
      sanitizer/_details.js
  10. 0
      sanitizer/_flag_bool.js
  11. 0
      sanitizer/_geo_autocomplete.js
  12. 2
      sanitizer/_geo_common.js
  13. 0
      sanitizer/_geo_reverse.js
  14. 0
      sanitizer/_geo_search.js
  15. 0
      sanitizer/_groups.js
  16. 0
      sanitizer/_ids.js
  17. 0
      sanitizer/_single_scalar_parameters.js
  18. 0
      sanitizer/_size.js
  19. 4
      sanitizer/_sources_and_layers.js
  20. 0
      sanitizer/_targets.js
  21. 0
      sanitizer/_text.js
  22. 0
      sanitizer/_text_addressit.js
  23. 0
      sanitizer/_tokenizer.js
  24. 34
      sanitizer/autocomplete.js
  25. 8
      sanitizer/nearby.js
  26. 10
      sanitizer/place.js
  27. 28
      sanitizer/reverse.js
  28. 0
      sanitizer/sanitizeAll.js
  29. 26
      sanitizer/search.js
  30. 6
      sanitizer/search_fallback.js
  31. 0
      sanitizer/wrap.js
  32. 2
      test/unit/fixture/search_boundary_country.js
  33. 2
      test/unit/fixture/search_linguistic_bbox.js
  34. 2
      test/unit/fixture/search_linguistic_focus.js
  35. 2
      test/unit/fixture/search_linguistic_focus_bbox.js
  36. 2
      test/unit/fixture/search_linguistic_focus_null_island.js
  37. 2
      test/unit/fixture/search_linguistic_only.js
  38. 2
      test/unit/fixture/search_linguistic_viewport.js
  39. 2
      test/unit/fixture/search_linguistic_viewport_min_diagonal.js
  40. 48
      test/unit/run.js
  41. 2
      test/unit/sanitizer/_boundary_country.js
  42. 2
      test/unit/sanitizer/_categories.js
  43. 2
      test/unit/sanitizer/_deprecate_quattroshapes.js
  44. 2
      test/unit/sanitizer/_flag_bool.js
  45. 2
      test/unit/sanitizer/_geo_common.js
  46. 2
      test/unit/sanitizer/_geo_reverse.js
  47. 2
      test/unit/sanitizer/_groups.js
  48. 2
      test/unit/sanitizer/_ids.js
  49. 2
      test/unit/sanitizer/_layers.js
  50. 2
      test/unit/sanitizer/_single_scalar_parameters.js
  51. 2
      test/unit/sanitizer/_size.js
  52. 2
      test/unit/sanitizer/_sources.js
  53. 2
      test/unit/sanitizer/_sources_and_layers.js
  54. 22
      test/unit/sanitizer/_text.js
  55. 32
      test/unit/sanitizer/_text_addressit.js
  56. 40
      test/unit/sanitizer/_tokenizer.js
  57. 2
      test/unit/sanitizer/_truthy.js
  58. 8
      test/unit/sanitizer/autocomplete.js
  59. 8
      test/unit/sanitizer/nearby.js
  60. 8
      test/unit/sanitizer/place.js
  61. 8
      test/unit/sanitizer/reverse.js
  62. 2
      test/unit/sanitizer/sanitizeAll.js
  63. 52
      test/unit/sanitizer/search.js
  64. 64
      test/unit/sanitizer/search_fallback.js
  65. 2
      test/unit/sanitizer/wrap.js

2
query/search.js

@ -59,7 +59,7 @@ function generateQuery( clean ){
// size // size
if( clean.querySize ) { if( clean.querySize ) {
vs.var( 'size', clean.querySize ); vs.var( 'size', 50 );
} }
// focus point // focus point

28
routes/v1.js

@ -2,14 +2,14 @@ var express = require('express');
var Router = require('express').Router; var Router = require('express').Router;
var reverseQuery = require('../query/reverse'); var reverseQuery = require('../query/reverse');
/** ----------------------- sanitisers ----------------------- **/ /** ----------------------- sanitizers ----------------------- **/
var sanitisers = { var sanitizers = {
autocomplete: require('../sanitiser/autocomplete'), autocomplete: require('../sanitizer/autocomplete'),
place: require('../sanitiser/place'), place: require('../sanitizer/place'),
search: require('../sanitiser/search'), search: require('../sanitizer/search'),
search_fallback: require('../sanitiser/search_fallback'), search_fallback: require('../sanitizer/search_fallback'),
reverse: require('../sanitiser/reverse'), reverse: require('../sanitizer/reverse'),
nearby: require('../sanitiser/nearby') nearby: require('../sanitizer/nearby')
}; };
/** ----------------------- middleware ------------------------ **/ /** ----------------------- middleware ------------------------ **/
@ -69,13 +69,13 @@ function addRoutes(app, peliasConfig) {
controllers.mdToHTML(peliasConfig, './public/attribution.md') controllers.mdToHTML(peliasConfig, './public/attribution.md')
]), ]),
search: createRouter([ search: createRouter([
sanitisers.search.middleware, sanitizers.search.middleware,
middleware.calcSize(), middleware.calcSize(),
// 2nd parameter is `backend` which gets initialized internally // 2nd parameter is `backend` which gets initialized internally
// 3rd parameter is which query module to use, use fallback/geodisambiguation // 3rd parameter is which query module to use, use fallback/geodisambiguation
// first, then use original search strategy if first query didn't return anything // first, then use original search strategy if first query didn't return anything
controllers.search(peliasConfig, undefined, queries.libpostal), controllers.search(peliasConfig, undefined, queries.libpostal),
sanitisers.search_fallback.middleware, sanitizers.search_fallback.middleware,
controllers.search(peliasConfig, undefined, queries.fallback_to_old_prod), controllers.search(peliasConfig, undefined, queries.fallback_to_old_prod),
postProc.trimByGranularity(), postProc.trimByGranularity(),
postProc.distances('focus.point.'), postProc.distances('focus.point.'),
@ -91,7 +91,7 @@ function addRoutes(app, peliasConfig) {
postProc.sendJSON postProc.sendJSON
]), ]),
autocomplete: createRouter([ autocomplete: createRouter([
sanitisers.autocomplete.middleware, sanitizers.autocomplete.middleware,
controllers.search(peliasConfig, null, require('../query/autocomplete')), controllers.search(peliasConfig, null, require('../query/autocomplete')),
postProc.distances('focus.point.'), postProc.distances('focus.point.'),
postProc.confidenceScores(peliasConfig), postProc.confidenceScores(peliasConfig),
@ -105,7 +105,7 @@ function addRoutes(app, peliasConfig) {
postProc.sendJSON postProc.sendJSON
]), ]),
reverse: createRouter([ reverse: createRouter([
sanitisers.reverse.middleware, sanitizers.reverse.middleware,
middleware.calcSize(), middleware.calcSize(),
controllers.search(peliasConfig, undefined, reverseQuery), controllers.search(peliasConfig, undefined, reverseQuery),
postProc.distances('point.'), postProc.distances('point.'),
@ -122,7 +122,7 @@ function addRoutes(app, peliasConfig) {
postProc.sendJSON postProc.sendJSON
]), ]),
nearby: createRouter([ nearby: createRouter([
sanitisers.nearby.middleware, sanitizers.nearby.middleware,
middleware.calcSize(), middleware.calcSize(),
controllers.search(peliasConfig, undefined, reverseQuery), controllers.search(peliasConfig, undefined, reverseQuery),
postProc.distances('point.'), postProc.distances('point.'),
@ -139,7 +139,7 @@ function addRoutes(app, peliasConfig) {
postProc.sendJSON postProc.sendJSON
]), ]),
place: createRouter([ place: createRouter([
sanitisers.place.middleware, sanitizers.place.middleware,
controllers.place(peliasConfig), controllers.place(peliasConfig),
postProc.accuracy(), postProc.accuracy(),
postProc.localNamingConventions(), postProc.localNamingConventions(),

34
sanitiser/autocomplete.js

@ -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();
});
};

28
sanitiser/reverse.js

@ -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();
});
};

26
sanitiser/search.js

@ -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();
});
};

0
sanitiser/_boundary_country.js → sanitizer/_boundary_country.js

0
sanitiser/_categories.js → sanitizer/_categories.js

0
sanitiser/_deprecate_quattroshapes.js → sanitizer/_deprecate_quattroshapes.js

0
sanitiser/_details.js → sanitizer/_details.js

0
sanitiser/_flag_bool.js → sanitizer/_flag_bool.js

0
sanitiser/_geo_autocomplete.js → sanitizer/_geo_autocomplete.js

2
sanitiser/_geo_common.js → sanitizer/_geo_common.js

@ -1,5 +1,5 @@
/** /**
* helper sanitiser methods for geo parameters * helper sanitizer methods for geo parameters
*/ */
var groups = require('./_groups'), var groups = require('./_groups'),
util = require('util'), util = require('util'),

0
sanitiser/_geo_reverse.js → sanitizer/_geo_reverse.js

0
sanitiser/_geo_search.js → sanitizer/_geo_search.js

0
sanitiser/_groups.js → sanitizer/_groups.js

0
sanitiser/_ids.js → sanitizer/_ids.js

0
sanitiser/_single_scalar_parameters.js → sanitizer/_single_scalar_parameters.js

0
sanitiser/_size.js → sanitizer/_size.js

4
sanitiser/_sources_and_layers.js → sanitizer/_sources_and_layers.js

@ -2,8 +2,8 @@ var _ = require( 'lodash' );
var type_mapping = require( '../helper/type_mapping' ); var type_mapping = require( '../helper/type_mapping' );
/* /*
* This sanitiser depends on clean.layers and clean.sources * This sanitizer depends on clean.layers and clean.sources
* so it has to be run after those sanitisers have been run * so it has to be run after those sanitizers have been run
*/ */
function sanitize( raw, clean ){ function sanitize( raw, clean ){
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };

0
sanitiser/_targets.js → sanitizer/_targets.js

0
sanitiser/_text.js → sanitizer/_text.js

0
sanitiser/_text_addressit.js → sanitizer/_text_addressit.js

0
sanitiser/_tokenizer.js → sanitizer/_tokenizer.js

34
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();
});
};

8
sanitiser/nearby.js → sanitizer/nearby.js

@ -1,17 +1,17 @@
var _ = require('lodash'); var _ = require('lodash');
var sanitizeAll = require('../sanitiser/sanitizeAll'); var sanitizeAll = require('../sanitizer/sanitizeAll');
var reverseSanitizers = require('./reverse').sanitiser_list; var reverseSanitizers = require('./reverse').sanitizer_list;
// add categories to the sanitizer list // add categories to the sanitizer list
var sanitizers = _.merge({}, reverseSanitizers, { var sanitizers = _.merge({}, reverseSanitizers, {
categories: require('../sanitiser/_categories') categories: require('../sanitizer/_categories')
}); });
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
// export sanitize for testing // export sanitize for testing
module.exports.sanitize = sanitize; module.exports.sanitize = sanitize;
module.exports.sanitiser_list = sanitizers; module.exports.sanitizer_list = sanitizers;
// middleware // middleware
module.exports.middleware = function( req, res, next ){ module.exports.middleware = function( req, res, next ){

10
sanitiser/place.js → sanitizer/place.js

@ -1,16 +1,16 @@
var sanitizeAll = require('../sanitiser/sanitizeAll'), var sanitizeAll = require('../sanitizer/sanitizeAll'),
sanitizers = { sanitizers = {
singleScalarParameters: require('../sanitiser/_single_scalar_parameters'), singleScalarParameters: require('../sanitizer/_single_scalar_parameters'),
ids: require('../sanitiser/_ids'), ids: require('../sanitizer/_ids'),
private: require('../sanitiser/_flag_bool')('private', false) private: require('../sanitizer/_flag_bool')('private', false)
}; };
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
// export sanitize for testing // export sanitize for testing
module.exports.sanitize = sanitize; module.exports.sanitize = sanitize;
module.exports.sanitiser_list = sanitizers; module.exports.sanitizer_list = sanitizers;
// middleware // middleware
module.exports.middleware = function( req, res, next ){ module.exports.middleware = function( req, res, next ){

28
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();
});
};

0
sanitiser/sanitizeAll.js → sanitizer/sanitizeAll.js

26
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();
});
};

6
sanitiser/search_fallback.js → sanitizer/search_fallback.js

@ -1,6 +1,6 @@
var sanitizeAll = require('../sanitiser/sanitizeAll'), var sanitizeAll = require('../sanitizer/sanitizeAll'),
sanitizers = { sanitizers = {
text: require('../sanitiser/_text_addressit') text: require('../sanitizer/_text_addressit')
}; };
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
@ -9,7 +9,7 @@ var logging = require( '../helper/logging' );
// middleware // middleware
module.exports.middleware = function( req, res, next ){ module.exports.middleware = function( req, res, next ){
// if res.data already has results then don't call the _text_autocomplete sanitiser // if res.data already has results then don't call the _text_autocomplete sanitizer
// this has been put into place for when the libpostal integration way of querying // this has been put into place for when the libpostal integration way of querying
// ES doesn't return anything and we want to fallback to the old logic // ES doesn't return anything and we want to fallback to the old logic
if (res && res.hasOwnProperty('data') && res.data.length > 0) { if (res && res.hasOwnProperty('data') && res.data.length > 0) {

0
sanitiser/wrap.js → sanitizer/wrap.js

2
test/unit/fixture/search_boundary_country.js

@ -73,7 +73,7 @@ module.exports = {
'boost_mode': 'multiply' 'boost_mode': 'multiply'
} }
}, },
'size': 10, 'size': 50,
'track_scores': true, 'track_scores': true,
'sort': [ 'sort': [
{ {

2
test/unit/fixture/search_linguistic_bbox.js

@ -76,7 +76,7 @@ module.exports = {
'boost_mode': 'multiply' 'boost_mode': 'multiply'
} }
}, },
'size': 10, 'size': 50,
'track_scores': true, 'track_scores': true,
'sort': [ 'sort': [
{ {

2
test/unit/fixture/search_linguistic_focus.js

@ -79,7 +79,7 @@ module.exports = {
'boost_mode': 'multiply' 'boost_mode': 'multiply'
} }
}, },
'size': 10, 'size': 50,
'track_scores': true, 'track_scores': true,
'sort': [ 'sort': [
{ {

2
test/unit/fixture/search_linguistic_focus_bbox.js

@ -90,7 +90,7 @@ module.exports = {
'boost_mode': 'multiply' 'boost_mode': 'multiply'
} }
}, },
'size': 10, 'size': 50,
'track_scores': true, 'track_scores': true,
'sort': [ 'sort': [
{ {

2
test/unit/fixture/search_linguistic_focus_null_island.js

@ -79,7 +79,7 @@ module.exports = {
'boost_mode': 'multiply' 'boost_mode': 'multiply'
} }
}, },
'size': 10, 'size': 50,
'track_scores': true, 'track_scores': true,
'sort': [ 'sort': [
{ {

2
test/unit/fixture/search_linguistic_only.js

@ -65,7 +65,7 @@ module.exports = {
'boost_mode': 'multiply' 'boost_mode': 'multiply'
} }
}, },
'size': 10, 'size': 50,
'track_scores': true, 'track_scores': true,
'sort': [ 'sort': [
{ {

2
test/unit/fixture/search_linguistic_viewport.js

@ -65,7 +65,7 @@ module.exports = {
'boost_mode': 'multiply' 'boost_mode': 'multiply'
} }
}, },
'size': 10, 'size': 50,
'track_scores': true, 'track_scores': true,
'sort': [ 'sort': [
{ {

2
test/unit/fixture/search_linguistic_viewport_min_diagonal.js

@ -65,7 +65,7 @@ module.exports = {
'boost_mode': 'multiply' 'boost_mode': 'multiply'
} }
}, },
'size': 10, 'size': 50,
'track_scores': true, 'track_scores': true,
'sort': [ 'sort': [
{ {

48
test/unit/run.js

@ -44,31 +44,31 @@ var tests = [
require('./query/search'), require('./query/search'),
require('./query/search_original'), require('./query/search_original'),
require('./query/text_parser'), require('./query/text_parser'),
require('./sanitiser/_boundary_country'), require('./sanitizer/_boundary_country'),
require('./sanitiser/_flag_bool'), require('./sanitizer/_flag_bool'),
require('./sanitiser/_geo_common'), require('./sanitizer/_geo_common'),
require('./sanitiser/_geo_reverse'), require('./sanitizer/_geo_reverse'),
require('./sanitiser/_groups'), require('./sanitizer/_groups'),
require('./sanitiser/_ids'), require('./sanitizer/_ids'),
require('./sanitiser/_layers'), require('./sanitizer/_layers'),
require('./sanitiser/_single_scalar_parameters'), require('./sanitizer/_single_scalar_parameters'),
require('./sanitiser/_size'), require('./sanitizer/_size'),
require('./sanitiser/_sources'), require('./sanitizer/_sources'),
require('./sanitiser/_sources_and_layers'), require('./sanitizer/_sources_and_layers'),
require('./sanitiser/_text'), require('./sanitizer/_text'),
require('./sanitiser/_text_addressit'), require('./sanitizer/_text_addressit'),
require('./sanitiser/_tokenizer'), require('./sanitizer/_tokenizer'),
require('./sanitiser/_deprecate_quattroshapes'), require('./sanitizer/_deprecate_quattroshapes'),
require('./sanitiser/_categories'), require('./sanitizer/_categories'),
require('./sanitiser/nearby'), require('./sanitizer/nearby'),
require('./src/backend'), require('./src/backend'),
require('./sanitiser/autocomplete'), require('./sanitizer/autocomplete'),
require('./sanitiser/place'), require('./sanitizer/place'),
require('./sanitiser/reverse'), require('./sanitizer/reverse'),
require('./sanitiser/sanitizeAll'), require('./sanitizer/sanitizeAll'),
require('./sanitiser/search'), require('./sanitizer/search'),
require('./sanitiser/search_fallback'), require('./sanitizer/search_fallback'),
require('./sanitiser/wrap'), require('./sanitizer/wrap'),
require('./service/mget'), require('./service/mget'),
require('./service/search') require('./service/search')
]; ];

2
test/unit/sanitiser/_boundary_country.js → 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 = {}; module.exports.tests = {};

2
test/unit/sanitiser/_categories.js → test/unit/sanitizer/_categories.js

@ -1,4 +1,4 @@
var sanitize = require( '../../../sanitiser/_categories'); var sanitize = require( '../../../sanitizer/_categories');
module.exports.tests = {}; module.exports.tests = {};

2
test/unit/sanitiser/_deprecate_quattroshapes.js → 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 = {}; module.exports.tests = {};

2
test/unit/sanitiser/_flag_bool.js → 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); var sanitize = sanitizer('dirty_param', true);
module.exports.tests = {}; module.exports.tests = {};

2
test/unit/sanitiser/_geo_common.js → 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 = {}; module.exports.tests = {};

2
test/unit/sanitiser/_geo_reverse.js → 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'); var defaults = require('../../../query/reverse_defaults');
module.exports.tests = {}; module.exports.tests = {};

2
test/unit/sanitiser/_groups.js → test/unit/sanitizer/_groups.js

@ -1,4 +1,4 @@
var groups = require('../../../sanitiser/_groups'); var groups = require('../../../sanitizer/_groups');
module.exports.tests = {}; module.exports.tests = {};

2
test/unit/sanitiser/_ids.js → test/unit/sanitizer/_ids.js

@ -1,4 +1,4 @@
var sanitize = require('../../../sanitiser/_ids'); var sanitize = require('../../../sanitizer/_ids');
var delimiter = ':'; var delimiter = ':';
var type_mapping = require('../../../helper/type_mapping'); var type_mapping = require('../../../helper/type_mapping');

2
test/unit/sanitiser/_layers.js → test/unit/sanitizer/_layers.js

@ -1,6 +1,6 @@
var type_mapping = require('../../../helper/type_mapping'); 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 = {}; module.exports.tests = {};

2
test/unit/sanitiser/_single_scalar_parameters.js → 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 = {}; module.exports.tests = {};

2
test/unit/sanitiser/_size.js → test/unit/sanitizer/_size.js

@ -1,4 +1,4 @@
var sanitize = require('../../../sanitiser/_size'); var sanitize = require('../../../sanitizer/_size');
module.exports.tests = {}; module.exports.tests = {};

2
test/unit/sanitiser/_sources.js → test/unit/sanitizer/_sources.js

@ -1,5 +1,5 @@
var type_mapping = require('../../../helper/type_mapping'); 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 }; var success_messages = { error: false };

2
test/unit/sanitiser/_sources_and_layers.js → 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'); var type_mapping = require('../../../helper/type_mapping');

22
test/unit/sanitiser/_text.js → test/unit/sanitizer/_text.js

@ -10,7 +10,7 @@ module.exports.tests.text_parser = function(test, common) {
key2: 'value 2' key2: 'value 2'
}; };
var sanitiser = proxyquire('../../../sanitiser/_text', { var sanitizer = proxyquire('../../../sanitizer/_text', {
'pelias-text-analyzer': { parse: function(query) { 'pelias-text-analyzer': { parse: function(query) {
return mock_analyzer_response; return mock_analyzer_response;
} }
@ -27,7 +27,7 @@ module.exports.tests.text_parser = function(test, common) {
parsed_text: mock_analyzer_response parsed_text: mock_analyzer_response
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEquals(clean, expected_clean); t.deepEquals(clean, expected_clean);
t.deepEquals(messages.errors, [], 'no errors'); 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) { 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) { 'pelias-text-analyzer': { parse: function(query) {
throw new Error('analyzer should not have been called'); 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 expected_clean = {
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEquals(clean, expected_clean); t.deepEquals(clean, expected_clean);
t.deepEquals(messages.errors, ['invalid param \'text\': text length, must be >0'], 'no errors'); 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) { 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) { 'pelias-text-analyzer': { parse: function(query) {
throw new Error('analyzer should not have been called'); 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 expected_clean = {
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEquals(clean, expected_clean); t.deepEquals(clean, expected_clean);
t.deepEquals(messages.errors, ['invalid param \'text\': text length, must be >0'], 'no errors'); 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) { 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) { 'pelias-text-analyzer': { parse: function(query) {
return undefined; return undefined;
} }
@ -105,7 +105,7 @@ module.exports.tests.text_parser = function(test, common) {
parsed_text: 'original clean.parsed_text' parsed_text: 'original clean.parsed_text'
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEquals(clean, expected_clean); t.deepEquals(clean, expected_clean);
t.deepEquals(messages.errors, [], 'no errors'); 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) { 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) { 'pelias-text-analyzer': { parse: function(query) {
return null; return null;
} }
@ -133,7 +133,7 @@ module.exports.tests.text_parser = function(test, common) {
parsed_text: 'original clean.parsed_text' parsed_text: 'original clean.parsed_text'
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEquals(clean, expected_clean); t.deepEquals(clean, expected_clean);
t.deepEquals(messages.errors, [], 'no errors'); t.deepEquals(messages.errors, [], 'no errors');
@ -146,7 +146,7 @@ module.exports.tests.text_parser = function(test, common) {
module.exports.all = function (tape, common) { module.exports.all = function (tape, common) {
function test(name, testFunction) { function test(name, testFunction) {
return tape('SANITISER _text: ' + name, testFunction); return tape('sanitizeR _text: ' + name, testFunction);
} }
for( var testCase in module.exports.tests ){ for( var testCase in module.exports.tests ){

32
test/unit/sanitiser/_text_addressit.js → test/unit/sanitizer/_text_addressit.js

@ -1,4 +1,4 @@
var sanitiser = require('../../../sanitiser/_text_addressit'); var sanitizer = require('../../../sanitizer/_text_addressit');
var type_mapping = require('../../../helper/type_mapping'); var type_mapping = require('../../../helper/type_mapping');
module.exports.tests = {}; module.exports.tests = {};
@ -11,7 +11,7 @@ module.exports.tests.text_parser = function(test, common) {
var clean = { var clean = {
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEquals(messages.errors, [], 'no errors'); t.deepEquals(messages.errors, [], 'no errors');
t.deepEquals(messages.warnings, [], 'no warnings'); t.deepEquals(messages.warnings, [], 'no warnings');
@ -41,7 +41,7 @@ module.exports.tests.text_parser = function(test, common) {
} }
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -65,7 +65,7 @@ module.exports.tests.text_parser = function(test, common) {
} }
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -95,7 +95,7 @@ module.exports.tests.text_parser = function(test, common) {
} }
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -118,7 +118,7 @@ module.exports.tests.text_parser = function(test, common) {
} }
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -139,7 +139,7 @@ module.exports.tests.text_parser = function(test, common) {
text: 'yugolsavia' text: 'yugolsavia'
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -158,7 +158,7 @@ module.exports.tests.text_parser = function(test, common) {
text: 'small town' text: 'small town'
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -177,7 +177,7 @@ module.exports.tests.text_parser = function(test, common) {
text: '123 main' text: '123 main'
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -196,7 +196,7 @@ module.exports.tests.text_parser = function(test, common) {
text: 'main 123' text: 'main 123'
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -219,7 +219,7 @@ module.exports.tests.text_parser = function(test, common) {
} }
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -243,7 +243,7 @@ module.exports.tests.text_parser = function(test, common) {
} }
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -268,7 +268,7 @@ module.exports.tests.text_parser = function(test, common) {
} }
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -293,7 +293,7 @@ module.exports.tests.text_parser = function(test, common) {
} }
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -318,7 +318,7 @@ module.exports.tests.text_parser = function(test, common) {
} }
}; };
var messages = sanitiser(raw, clean); var messages = sanitizer(raw, clean);
t.deepEqual(messages, { errors: [], warnings: [] } ); t.deepEqual(messages, { errors: [], warnings: [] } );
t.deepEqual(clean, expected_clean); t.deepEqual(clean, expected_clean);
@ -330,7 +330,7 @@ module.exports.tests.text_parser = function(test, common) {
module.exports.all = function (tape, common) { module.exports.all = function (tape, common) {
function test(name, testFunction) { function test(name, testFunction) {
return tape('SANITISER _text: ' + name, testFunction); return tape('sanitizeR _text: ' + name, testFunction);
} }
for( var testCase in module.exports.tests ){ for( var testCase in module.exports.tests ){

40
test/unit/sanitiser/_tokenizer.js → test/unit/sanitizer/_tokenizer.js

@ -1,4 +1,4 @@
var sanitiser = require('../../../sanitiser/_tokenizer'); var sanitizer = require('../../../sanitizer/_tokenizer');
module.exports.tests = {}; module.exports.tests = {};
@ -6,7 +6,7 @@ module.exports.tests.sanity_checks = function(test, common) {
test('clean.text not set', function(t) { test('clean.text not set', function(t) {
var clean = {}; // clean.text not set var clean = {}; // clean.text not set
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// no tokens produced // no tokens produced
t.deepEquals(clean.tokens, [], 'no tokens'); 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) { test('clean.text not a string', function(t) {
var clean = { text: {} }; // clean.text not a string var clean = { text: {} }; // clean.text not a string
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// no tokens produced // no tokens produced
t.deepEquals(clean.tokens, [], 'no tokens'); t.deepEquals(clean.tokens, [], 'no tokens');
@ -38,7 +38,7 @@ module.exports.tests.sanity_checks = function(test, common) {
test('empty string', function(t) { test('empty string', function(t) {
var clean = { text: '' }; var clean = { text: '' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// no tokens produced // no tokens produced
t.deepEquals(clean.tokens, [], 'no tokens'); 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) { test('clean.parsed_text set but clean.parsed_text.name invalid', function(t) {
var clean = { parsed_text: { text: {} } }; var clean = { parsed_text: { text: {} } };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// no tokens produced // no tokens produced
t.deepEquals(clean.tokens, [], 'no tokens'); 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) { test('favor clean.parsed_text.name over clean.text', function(t) {
var clean = { parsed_text: { name: 'foo' }, text: 'bar' }; var clean = { parsed_text: { name: 'foo' }, text: 'bar' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// favor clean.parsed_text.name over clean.text // favor clean.parsed_text.name over clean.text
t.deepEquals(clean.tokens, [ 'foo' ], 'use clean.parsed_text.name'); 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) { test('favor clean.parsed_text street data over clean.text', function(t) {
var clean = { parsed_text: { number: '190', street: 'foo st' }, text: 'bar' }; 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 // favor clean.parsed_text.name over clean.text
t.deepEquals(clean.tokens, [ '190', 'foo', 'st' ], 'use street name + number'); 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) { 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 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 // favor clean.parsed_text.name over all other variables
t.deepEquals(clean.tokens, [ 'foo' ], 'use clean.parsed_text.name'); 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) { test('space delimiter - simple', function(t) {
var clean = { text: '30 west 26th street new york' }; var clean = { text: '30 west 26th street new york' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// tokens produced // tokens produced
t.deepEquals(clean.tokens, [ 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) { test('space delimiter - multiple spaces / other whitespace', function(t) {
var clean = { text: ' 30 west \t26th \nstreet new york ' }; var clean = { text: ' 30 west \t26th \nstreet new york ' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// tokens produced // tokens produced
t.deepEquals(clean.tokens, [ t.deepEquals(clean.tokens, [
@ -194,7 +194,7 @@ module.exports.tests.comma_delimiter = function(test, common) {
test('comma delimiter - simple', function(t) { test('comma delimiter - simple', function(t) {
var clean = { text: '30 west 26th street, new york' }; var clean = { text: '30 west 26th street, new york' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// tokens produced // tokens produced
t.deepEquals(clean.tokens, [ t.deepEquals(clean.tokens, [
@ -229,7 +229,7 @@ module.exports.tests.comma_delimiter = function(test, common) {
test('comma delimiter - multiple commas', function(t) { test('comma delimiter - multiple commas', function(t) {
var clean = { text: ',30 west 26th street,,, new york,' }; var clean = { text: ',30 west 26th street,,, new york,' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// tokens produced // tokens produced
t.deepEquals(clean.tokens, [ t.deepEquals(clean.tokens, [
@ -267,7 +267,7 @@ module.exports.tests.forward_slash_delimiter = function(test, common) {
test('forward slash delimiter - simple', function(t) { test('forward slash delimiter - simple', function(t) {
var clean = { text: 'Bedell Street/133rd Avenue' }; var clean = { text: 'Bedell Street/133rd Avenue' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// tokens produced // tokens produced
t.deepEquals(clean.tokens, [ t.deepEquals(clean.tokens, [
@ -298,7 +298,7 @@ module.exports.tests.forward_slash_delimiter = function(test, common) {
test('forward slash - multiple slashes', function(t) { test('forward slash - multiple slashes', function(t) {
var clean = { text: '/Bedell Street//133rd Avenue/' }; var clean = { text: '/Bedell Street//133rd Avenue/' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// tokens produced // tokens produced
t.deepEquals(clean.tokens, [ 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) { test('final token single gram - numeric', function(t) {
var clean = { text: 'grolmanstrasse 1' }; var clean = { text: 'grolmanstrasse 1' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// tokens produced // tokens produced
t.deepEquals(clean.tokens, [ 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) { test('final token single gram - non-numeric', function(t) {
var clean = { text: 'grolmanstrasse a' }; var clean = { text: 'grolmanstrasse a' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// tokens produced // tokens produced
t.deepEquals(clean.tokens, [ t.deepEquals(clean.tokens, [
@ -389,7 +389,7 @@ module.exports.tests.back_slash_delimiter = function(test, common) {
test('back slash delimiter - simple', function(t) { test('back slash delimiter - simple', function(t) {
var clean = { text: 'Bedell Street\\133rd Avenue' }; var clean = { text: 'Bedell Street\\133rd Avenue' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// tokens produced // tokens produced
t.deepEquals(clean.tokens, [ t.deepEquals(clean.tokens, [
@ -408,7 +408,7 @@ module.exports.tests.back_slash_delimiter = function(test, common) {
test('back slash - multiple slashes', function(t) { test('back slash - multiple slashes', function(t) {
var clean = { text: '\\Bedell Street\\\\133rd Avenue\\' }; var clean = { text: '\\Bedell Street\\\\133rd Avenue\\' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// tokens produced // tokens produced
t.deepEquals(clean.tokens, [ t.deepEquals(clean.tokens, [
@ -430,7 +430,7 @@ module.exports.tests.mixed_delimiter = function(test, common) {
test('mixed delimiters', function(t) { test('mixed delimiters', function(t) {
var clean = { text: ',/Bedell Street\\, \n\t ,\\//133rd Avenue, /\n/' }; var clean = { text: ',/Bedell Street\\, \n\t ,\\//133rd Avenue, /\n/' };
var messages = sanitiser({}, clean); var messages = sanitizer({}, clean);
// tokens produced // tokens produced
t.deepEquals(clean.tokens, [ t.deepEquals(clean.tokens, [
@ -450,7 +450,7 @@ module.exports.tests.mixed_delimiter = function(test, common) {
module.exports.all = function (tape, common) { module.exports.all = function (tape, common) {
function test(name, testFunction) { function test(name, testFunction) {
return tape('SANITISER _tokenizer: ' + name, testFunction); return tape('sanitizeR _tokenizer: ' + name, testFunction);
} }
for( var testCase in module.exports.tests ){ for( var testCase in module.exports.tests ){

2
test/unit/sanitiser/_truthy.js → test/unit/sanitizer/_truthy.js

@ -1,4 +1,4 @@
var isTruthy = require('../../../sanitiser/_truthy'); var isTruthy = require('../../../sanitizer/_truthy');
module.exports.tests = {}; module.exports.tests = {};

8
test/unit/sanitiser/autocomplete.js → 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 = {};
module.exports.tests.sanitisers = function(test, common) { module.exports.tests.sanitizers = function(test, common) {
test('check sanitiser list', function (t) { test('check sanitizer list', function (t) {
var expected = [ var expected = [
'singleScalarParameters', 'text', 'tokenizer', 'size', 'layers', 'sources', 'singleScalarParameters', 'text', 'tokenizer', 'size', 'layers', 'sources',
'sources_and_layers', 'private', 'geo_autocomplete', 'boundary_country', 'categories' '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(); t.end();
}); });
}; };

8
test/unit/sanitiser/nearby.js → 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 defaults = require('../../../query/reverse_defaults');
var sanitize = nearby.sanitize; var sanitize = nearby.sanitize;
var middleware = nearby.middleware; var middleware = nearby.middleware;
@ -28,11 +28,11 @@ module.exports.tests.interface = function(test, common) {
}); });
}; };
module.exports.tests.sanitisers = function(test, common) { module.exports.tests.sanitizers = function(test, common) {
test('check sanitiser list', function (t) { test('check sanitizer list', function (t) {
var expected = ['quattroshapes_deprecation', 'singleScalarParameters', 'layers', var expected = ['quattroshapes_deprecation', 'singleScalarParameters', 'layers',
'sources', 'sources_and_layers', 'size', 'private', 'geo_reverse', 'boundary_country', 'categories']; '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(); t.end();
}); });
}; };

8
test/unit/sanitiser/place.js → test/unit/sanitizer/place.js

@ -1,4 +1,4 @@
var place = require('../../../sanitiser/place'), var place = require('../../../sanitizer/place'),
sanitize = place.sanitize, sanitize = place.sanitize,
middleware = place.middleware, middleware = place.middleware,
defaultClean = { ids: [ { source: 'geonames', layer: 'venue', id: '123' } ], private: false }; 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) { module.exports.tests.sanitizers = function(test, common) {
test('check sanitiser list', function (t) { test('check sanitizer list', function (t) {
var expected = ['singleScalarParameters', 'ids', 'private' ]; var expected = ['singleScalarParameters', 'ids', 'private' ];
t.deepEqual(Object.keys(place.sanitiser_list), expected); t.deepEqual(Object.keys(place.sanitizer_list), expected);
t.end(); t.end();
}); });
}; };

8
test/unit/sanitiser/reverse.js → test/unit/sanitizer/reverse.js

@ -1,7 +1,7 @@
// @todo: refactor this test, it's pretty messy, brittle and hard to follow // @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, sanitize = reverse.sanitize,
middleware = reverse.middleware, middleware = reverse.middleware,
defaults = require('../../../query/reverse_defaults'), defaults = require('../../../query/reverse_defaults'),
@ -34,11 +34,11 @@ module.exports.tests.interface = function(test, common) {
}); });
}; };
module.exports.tests.sanitisers = function(test, common) { module.exports.tests.sanitizers = function(test, common) {
test('check sanitiser list', function (t) { test('check sanitizer list', function (t) {
var expected = ['quattroshapes_deprecation', 'singleScalarParameters', 'layers', var expected = ['quattroshapes_deprecation', 'singleScalarParameters', 'layers',
'sources', 'sources_and_layers', 'size', 'private', 'geo_reverse', 'boundary_country']; '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(); t.end();
}); });
}; };

2
test/unit/sanitiser/sanitizeAll.js → test/unit/sanitizer/sanitizeAll.js

@ -1,4 +1,4 @@
var sanitizeAll = require('../../../sanitiser/sanitizeAll'); var sanitizeAll = require('../../../sanitizer/sanitizeAll');
module.exports.tests = {}; module.exports.tests = {};

52
test/unit/sanitiser/search.js → test/unit/sanitizer/search.js

@ -3,28 +3,28 @@ var proxyquire = require('proxyquire').noCallThru();
module.exports.tests = {}; module.exports.tests = {};
module.exports.tests.sanitize = function(test, common) { module.exports.tests.sanitize = function(test, common) {
test('verify that all sanitisers were called as expected', function(t) { test('verify that all sanitizers were called as expected', function(t) {
var called_sanitisers = []; 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 // were all called correctly
var search = proxyquire('../../../sanitiser/search', { var search = proxyquire('../../../sanitizer/search', {
'../sanitiser/_deprecate_quattroshapes': function() { '../sanitizer/_deprecate_quattroshapes': function() {
called_sanitisers.push('_deprecate_quattroshapes'); called_sanitizers.push('_deprecate_quattroshapes');
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
}, },
'../sanitiser/_single_scalar_parameters': function() { '../sanitizer/_single_scalar_parameters': function() {
called_sanitisers.push('_single_scalar_parameters'); called_sanitizers.push('_single_scalar_parameters');
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
}, },
'../sanitiser/_text': function() { '../sanitizer/_text': function() {
called_sanitisers.push('_text'); called_sanitizers.push('_text');
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
}, },
'../sanitiser/_size': function() { '../sanitizer/_size': function() {
if (arguments.length === 0) { if (arguments.length === 0) {
return function() { return function() {
called_sanitisers.push('_size'); called_sanitizers.push('_size');
return { errors: [], warnings: [] }; 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) { if (['layers', 'sources'].indexOf(type) !== -1) {
return function() { return function() {
called_sanitisers.push('_targets/' + type); called_sanitizers.push('_targets/' + type);
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
}; };
@ -46,14 +46,14 @@ module.exports.tests.sanitize = function(test, common) {
} }
}, },
'../sanitiser/_sources_and_layers': function() { '../sanitizer/_sources_and_layers': function() {
called_sanitisers.push('_sources_and_layers'); called_sanitizers.push('_sources_and_layers');
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
}, },
'../sanitiser/_flag_bool': function() { '../sanitizer/_flag_bool': function() {
if (arguments[0] === 'private' && arguments[1] === false) { if (arguments[0] === 'private' && arguments[1] === false) {
return function() { return function() {
called_sanitisers.push('_flag_bool'); called_sanitizers.push('_flag_bool');
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
}; };
@ -63,21 +63,21 @@ module.exports.tests.sanitize = function(test, common) {
} }
}, },
'../sanitiser/_geo_search': function() { '../sanitizer/_geo_search': function() {
called_sanitisers.push('_geo_search'); called_sanitizers.push('_geo_search');
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
}, },
'../sanitiser/_boundary_country': function() { '../sanitizer/_boundary_country': function() {
called_sanitisers.push('_boundary_country'); called_sanitizers.push('_boundary_country');
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
}, },
'../sanitiser/_categories': function() { '../sanitizer/_categories': function() {
called_sanitisers.push('_categories'); called_sanitizers.push('_categories');
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
}, },
}); });
var expected_sanitisers = [ var expected_sanitizers = [
'_deprecate_quattroshapes', '_deprecate_quattroshapes',
'_single_scalar_parameters', '_single_scalar_parameters',
'_text', '_text',
@ -95,7 +95,7 @@ module.exports.tests.sanitize = function(test, common) {
var res = {}; var res = {};
search.middleware(req, res, function(){ search.middleware(req, res, function(){
t.deepEquals(called_sanitisers, expected_sanitisers); t.deepEquals(called_sanitizers, expected_sanitizers);
t.end(); t.end();
}); });
}); });

64
test/unit/sanitiser/search_fallback.js → test/unit/sanitizer/search_fallback.js

@ -3,44 +3,44 @@ var proxyquire = require('proxyquire').noCallThru();
module.exports.tests = {}; module.exports.tests = {};
module.exports.tests.sanitize = function(test, common) { module.exports.tests.sanitize = function(test, common) {
test('verify that all sanitisers were called as expected when `res` is undefined', function(t) { test('verify that all sanitizers were called as expected when `res` is undefined', function(t) {
var called_sanitisers = []; 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 // were all called correctly
var search = proxyquire('../../../sanitiser/search_fallback', { var search = proxyquire('../../../sanitizer/search_fallback', {
'../sanitiser/_text_addressit': function() { '../sanitizer/_text_addressit': function() {
called_sanitisers.push('_text_addressit'); called_sanitizers.push('_text_addressit');
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
} }
}); });
var expected_sanitisers = [ var expected_sanitizers = [
'_text_addressit' '_text_addressit'
]; ];
var req = {}; var req = {};
search.middleware(req, undefined, function(){ search.middleware(req, undefined, function(){
t.deepEquals(called_sanitisers, expected_sanitisers); t.deepEquals(called_sanitizers, expected_sanitizers);
t.end(); t.end();
}); });
}); });
test('verify that all sanitisers were called as expected when `res` has no `data` property', function(t) { test('verify that all sanitizers were called as expected when `res` has no `data` property', function(t) {
var called_sanitisers = []; 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 // were all called correctly
var search = proxyquire('../../../sanitiser/search_fallback', { var search = proxyquire('../../../sanitizer/search_fallback', {
'../sanitiser/_text_addressit': function() { '../sanitizer/_text_addressit': function() {
called_sanitisers.push('_text_addressit'); called_sanitizers.push('_text_addressit');
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
} }
}); });
var expected_sanitisers = [ var expected_sanitizers = [
'_text_addressit' '_text_addressit'
]; ];
@ -48,25 +48,25 @@ module.exports.tests.sanitize = function(test, common) {
var res = {}; var res = {};
search.middleware(req, res, function(){ search.middleware(req, res, function(){
t.deepEquals(called_sanitisers, expected_sanitisers); t.deepEquals(called_sanitizers, expected_sanitizers);
t.end(); t.end();
}); });
}); });
test('verify that all sanitisers were called as expected when res.data is empty', function(t) { test('verify that all sanitizers were called as expected when res.data is empty', function(t) {
var called_sanitisers = []; 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 // were all called correctly
var search = proxyquire('../../../sanitiser/search_fallback', { var search = proxyquire('../../../sanitizer/search_fallback', {
'../sanitiser/_text_addressit': function() { '../sanitizer/_text_addressit': function() {
called_sanitisers.push('_text_addressit'); called_sanitizers.push('_text_addressit');
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
} }
}); });
var expected_sanitisers = [ var expected_sanitizers = [
'_text_addressit' '_text_addressit'
]; ];
@ -76,24 +76,24 @@ module.exports.tests.sanitize = function(test, common) {
}; };
search.middleware(req, res, function(){ search.middleware(req, res, function(){
t.deepEquals(called_sanitisers, expected_sanitisers); t.deepEquals(called_sanitizers, expected_sanitizers);
t.end(); t.end();
}); });
}); });
test('non-empty res.data should not call the _text_autocomplete sanitiser', function(t) { test('non-empty res.data should not call the _text_autocomplete sanitizer', function(t) {
var called_sanitisers = []; 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 // were all called correctly
var search = proxyquire('../../../sanitiser/search_fallback', { var search = proxyquire('../../../sanitizer/search_fallback', {
'../sanitiser/_text_autocomplete': function() { '../sanitizer/_text_autocomplete': function() {
throw new Error('_text_autocomplete sanitiser should not have been called'); throw new Error('_text_autocomplete sanitizer should not have been called');
} }
}); });
var expected_sanitisers = []; var expected_sanitizers = [];
var req = {}; var req = {};
var res = { var res = {
@ -101,7 +101,7 @@ module.exports.tests.sanitize = function(test, common) {
}; };
search.middleware(req, res, function(){ search.middleware(req, res, function(){
t.deepEquals(called_sanitisers, expected_sanitisers); t.deepEquals(called_sanitizers, expected_sanitizers);
t.end(); t.end();
}); });

2
test/unit/sanitiser/wrap.js → test/unit/sanitizer/wrap.js

@ -1,5 +1,5 @@
var wrap = require('../../../sanitiser/wrap'); var wrap = require('../../../sanitizer/wrap');
module.exports.tests = {}; module.exports.tests = {};
Loading…
Cancel
Save