diff --git a/sanitiser/_boundary_country.js b/sanitiser/_boundary_country.js index 05760f73..2a586252 100644 --- a/sanitiser/_boundary_country.js +++ b/sanitiser/_boundary_country.js @@ -20,7 +20,7 @@ function sanitize(raw, clean) { clean.boundary.country = undefined; } else { - clean.boundary.country = iso3166.to2(country.toUpperCase()); + clean.boundary.country = iso3166.to3(country.toUpperCase()); } } else { @@ -32,9 +32,9 @@ function sanitize(raw, clean) { } function containsIsoCode(isoCode) { - return iso3166.list().filter(function(row) { + return iso3166.list().some(function(row) { return row.alpha2 === isoCode || row.alpha3 === isoCode; - }).length > 0; + }); } module.exports = sanitize; diff --git a/sanitiser/search.js b/sanitiser/search.js index dd042761..2c867b54 100644 --- a/sanitiser/search.js +++ b/sanitiser/search.js @@ -7,7 +7,8 @@ var sanitizeAll = require('../sanitiser/sanitizeAll'), sources: require('../sanitiser/_targets')('sources', require( '../query/sources' )), details: require('../sanitiser/_details'), geo_search: require('../sanitiser/_geo_search'), - categories: require('../sanitiser/_categories') + categories: require('../sanitiser/_categories'), + boundary_country: require('../sanitiser/_boundary_country'), }; var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; @@ -26,4 +27,3 @@ module.exports.middleware = function( req, res, next ){ next(); }); }; - diff --git a/test/unit/sanitiser/_boundary_country.js b/test/unit/sanitiser/_boundary_country.js index 68816f3d..de70cb8b 100644 --- a/test/unit/sanitiser/_boundary_country.js +++ b/test/unit/sanitiser/_boundary_country.js @@ -39,20 +39,20 @@ module.exports.tests.sanitize_boundary_country = function(test, common) { t.end(); }); - test('iso2 boundary.country in raw should set boundary.country to ISO2 uppercased', function(t) { + test('iso2 boundary.country in raw should set boundary.country to ISO3 uppercased', function(t) { var raw = { boundary: {country: 'aq'} }; var clean = {}; var errorsAndWarnings = sanitize(raw, clean); - t.equals(clean.boundary.country, 'AQ', 'should be uppercased ISO2'); + t.equals(clean.boundary.country, 'ATA', 'should be uppercased ISO3'); t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'no warnings or errors'); t.end(); }); - test('iso3 boundary.country in raw should set boundary.country to matching ISO2 uppercased', function(t) { + test('iso3 boundary.country in raw should set boundary.country to matching ISO3 uppercased', function(t) { var raw = { boundary: {country: 'aTa'} }; var clean = {}; var errorsAndWarnings = sanitize(raw, clean); - t.equals(clean.boundary.country, 'AQ', 'should be uppercased ISO2'); + t.equals(clean.boundary.country, 'ATA', 'should be uppercased ISO3'); t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'no warnings or errors'); t.end(); }); diff --git a/test/unit/sanitiser/search.js b/test/unit/sanitiser/search.js index e6c39284..0ed32e4c 100644 --- a/test/unit/sanitiser/search.js +++ b/test/unit/sanitiser/search.js @@ -32,7 +32,7 @@ module.exports.tests.interface = function(test, common) { module.exports.tests.sanitisers = function(test, common) { test('check sanitiser list', function (t) { - var expected = ['text', 'size', 'layers', 'sources', 'details', 'geo_search', 'categories' ]; + var expected = ['text', 'size', 'layers', 'sources', 'details', 'geo_search', 'categories', 'boundary_country' ]; t.deepEqual(Object.keys(search.sanitiser_list), expected); t.end(); }); @@ -77,7 +77,7 @@ module.exports.tests.sanitise_valid_text = function(test, common) { module.exports.tests.sanitize_text_with_delim = function(test, common) { var texts = [ 'a,bcd', '123 main st, admin1', ',,,', ' ' ]; - test('valid texts with a comma', function(t) { + test('valid texts with a comma', function(t) { texts.forEach( function( text ){ sanitize({ text: text }, function( err, clean ){ var expected = JSON.parse(JSON.stringify( defaultClean ));