Browse Source

modified sanitizer to read from flattened parameter structure

pull/253/head
Stephen Hess 9 years ago
parent
commit
78c335d072
  1. 4
      sanitiser/_boundary_country.js
  2. 21
      test/unit/sanitiser/_boundary_country.js

4
sanitiser/_boundary_country.js

@ -8,8 +8,8 @@ function sanitize(raw, clean) {
// init clean.boundary (if not already init) // init clean.boundary (if not already init)
clean.boundary = clean.boundary || {}; clean.boundary = clean.boundary || {};
if (raw.boundary && raw.boundary.country) { if (raw['boundary.country']) {
var country = raw.boundary.country var country = raw['boundary.country'];
if (typeof country !== 'string') { if (typeof country !== 'string') {
messages.warnings.push('boundary.country is not a string'); messages.warnings.push('boundary.country is not a string');

21
test/unit/sanitiser/_boundary_country.js

@ -12,17 +12,8 @@ module.exports.tests.sanitize_boundary_country = function(test, common) {
t.end(); t.end();
}); });
test('boundary w/o country in raw should leave boundary.country undefined', function(t) {
var raw = { boundary: {} };
var clean = {};
var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, undefined, 'should be undefined');
t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'no warnings or errors');
t.end();
});
test('boundary.country explicitly undefined in raw should leave boundary.country undefined', function(t) { test('boundary.country explicitly undefined in raw should leave boundary.country undefined', function(t) {
var raw = { boundary: {country: undefined } }; var raw = { 'boundary.country': undefined };
var clean = {}; var clean = {};
var errorsAndWarnings = sanitize(raw, clean); var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, undefined, 'should be undefined'); t.equals(clean.boundary.country, undefined, 'should be undefined');
@ -31,7 +22,7 @@ module.exports.tests.sanitize_boundary_country = function(test, common) {
}); });
test('non-string boundary.country should set boundary.country to undefined and return warning', function(t) { test('non-string boundary.country should set boundary.country to undefined and return warning', function(t) {
var raw = { boundary: {country: ['this isn\'t a string primitive'] } }; var raw = { 'boundary.country': ['this isn\'t a string primitive'] };
var clean = {}; var clean = {};
var errorsAndWarnings = sanitize(raw, clean); var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, undefined, 'should be undefined'); t.equals(clean.boundary.country, undefined, 'should be undefined');
@ -40,7 +31,7 @@ module.exports.tests.sanitize_boundary_country = function(test, common) {
}); });
test('iso2 boundary.country in raw should set boundary.country to ISO3 uppercased', function(t) { test('iso2 boundary.country in raw should set boundary.country to ISO3 uppercased', function(t) {
var raw = { boundary: {country: 'aq'} }; var raw = { 'boundary.country': 'aq' };
var clean = {}; var clean = {};
var errorsAndWarnings = sanitize(raw, clean); var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, 'ATA', 'should be uppercased ISO3'); t.equals(clean.boundary.country, 'ATA', 'should be uppercased ISO3');
@ -49,7 +40,7 @@ module.exports.tests.sanitize_boundary_country = function(test, common) {
}); });
test('iso3 boundary.country in raw should set boundary.country to matching ISO3 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 raw = { 'boundary.country': 'aTa' };
var clean = {}; var clean = {};
var errorsAndWarnings = sanitize(raw, clean); var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, 'ATA', 'should be uppercased ISO3'); t.equals(clean.boundary.country, 'ATA', 'should be uppercased ISO3');
@ -58,7 +49,7 @@ module.exports.tests.sanitize_boundary_country = function(test, common) {
}); });
test('unknown 2-character boundary.country should set boundary.country to undefined', function(t) { test('unknown 2-character boundary.country should set boundary.country to undefined', function(t) {
var raw = { boundary: {country: 'zq'} }; var raw = { 'boundary.country': 'zq' };
var clean = {}; var clean = {};
var errorsAndWarnings = sanitize(raw, clean); var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, undefined, 'should be undefined'); t.equals(clean.boundary.country, undefined, 'should be undefined');
@ -67,7 +58,7 @@ module.exports.tests.sanitize_boundary_country = function(test, common) {
}); });
test('unknown 3-character boundary.country should set boundary.country to undefined', function(t) { test('unknown 3-character boundary.country should set boundary.country to undefined', function(t) {
var raw = { boundary: {country: 'zqx'} }; var raw = { 'boundary.country': 'zqx' };
var clean = {}; var clean = {};
var errorsAndWarnings = sanitize(raw, clean); var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, undefined, 'should be undefined'); t.equals(clean.boundary.country, undefined, 'should be undefined');

Loading…
Cancel
Save