diff --git a/sanitiser/_boundary_country.js b/sanitiser/_boundary_country.js index f2824cec..192a9167 100644 --- a/sanitiser/_boundary_country.js +++ b/sanitiser/_boundary_country.js @@ -1,4 +1,4 @@ -var isObject = require('is-object'); +var check = require('check-types'); var iso3166 = require('iso3166-1'); function sanitize(raw, clean) { @@ -8,23 +8,25 @@ function sanitize(raw, clean) { // init clean.boundary (if not already init) clean.boundary = clean.boundary || {}; - if (raw['boundary.country']) { + if (check.assigned(raw['boundary.country'])) { var country = raw['boundary.country']; - if (typeof country !== 'string') { + if (!check.string(country)) { messages.warnings.push('boundary.country is not a string'); - clean.boundary.country = undefined; + delete clean.boundary.country; } else if (!containsIsoCode(country.toUpperCase())) { messages.warnings.push(country + ' is not a valid ISO2/ISO3 country code'); - clean.boundary.country = undefined; + delete clean.boundary.country; } else { + // the only way for boundary.country to be assigned is if input is + // a string and a known ISO2 or ISO3 clean.boundary.country = iso3166.to3(country.toUpperCase()); } } else { - clean.boundary.country = undefined; + delete clean.boundary.country; } return messages; diff --git a/test/unit/sanitiser/reverse.js b/test/unit/sanitiser/reverse.js index 1529c1e1..f181b69b 100644 --- a/test/unit/sanitiser/reverse.js +++ b/test/unit/sanitiser/reverse.js @@ -10,7 +10,7 @@ var reverse = require('../../../sanitiser/reverse'), size: 10, details: true, categories: [], - boundary: { country: undefined } + boundary: { } }, sanitize = function(query, cb) { _sanitize({'query':query}, cb); };