Browse Source

requirements updates

set boundary country to iso3 instead of iso2
set to undefined if boundary.country input is not a string
pull/253/head
Stephen Hess 10 years ago
parent
commit
d07a501682
  1. 6
      sanitiser/_boundary_country.js
  2. 4
      sanitiser/search.js
  3. 8
      test/unit/sanitiser/_boundary_country.js
  4. 4
      test/unit/sanitiser/search.js

6
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;

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

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

4
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 ));

Loading…
Cancel
Save