diff --git a/sanitizer/_details.js b/sanitizer/_details.js deleted file mode 100644 index c67f7c47..00000000 --- a/sanitizer/_details.js +++ /dev/null @@ -1,32 +0,0 @@ - -var _ = require('lodash'), - check = require('check-types'); - -var DEFAULT_DETAILS_BOOL = true; - -// validate inputs, convert types and apply defaults -function sanitize( raw, clean ){ - - // error & warning messages - var messages = { errors: [], warnings: [] }; - - if( !check.undefined( raw.details ) ){ - clean.details = isTruthy( raw.details ); - } else { - clean.details = DEFAULT_DETAILS_BOOL; - } - - return messages; -} - -// be lenient with 'truthy' values -function isTruthy(val) { - if( check.string( val ) ){ - return _.includes( ['true', '1'], val ); - } - - return val === 1 || val === true; -} - -// export function -module.exports = sanitize; diff --git a/sanitizer/search.js b/sanitizer/search.js index 5694c9eb..3ee20246 100644 --- a/sanitizer/search.js +++ b/sanitizer/search.js @@ -15,7 +15,8 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'), private: require('../sanitizer/_flag_bool')('private', false), geo_search: require('../sanitizer/_geo_search'), boundary_country: require('../sanitizer/_boundary_country'), - categories: require('../sanitizer/_categories') + categories: require('../sanitizer/_categories'), + debug: require('../sanitizer/_debug') }; var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; diff --git a/test/unit/run.js b/test/unit/run.js index 71b14e27..182eef0b 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -44,6 +44,7 @@ var tests = [ require('./query/structured_geocoding'), require('./query/text_parser'), require('./sanitizer/_boundary_country'), + require('./sanitizer/_debug'), require('./sanitizer/_flag_bool'), require('./sanitizer/_geo_common'), require('./sanitizer/_geo_reverse'), diff --git a/test/unit/sanitizer/_truthy.js b/test/unit/sanitizer/_truthy.js deleted file mode 100644 index 932a840b..00000000 --- a/test/unit/sanitizer/_truthy.js +++ /dev/null @@ -1,31 +0,0 @@ -var isTruthy = require('../../../sanitizer/_truthy'); - -module.exports.tests = {}; - -module.exports.tests.sanitize_truthy = function(test, common) { - var valid_values = ['true', true, 1, '1', 'yes', 'y']; - valid_values.forEach(function(value) { - test('truthy value ' + value, function(t) { - t.equal(isTruthy(value), true, 'returns true'); - t.end(); - }); - }); - - var valid_false_values = ['false', false, 0, '0', 'no', 'n', null, -1, 123, NaN, 'abc']; - valid_false_values.forEach(function(value) { - test('falsey value ' + value, function(t) { - t.equal(isTruthy(value), false, 'returns false'); - t.end(); - }); - }); -}; - -module.exports.all = function (tape, common) { - function test(name, testFunction) { - return tape('SANTIZE _truthy ' + name, testFunction); - } - - for( var testCase in module.exports.tests ){ - module.exports.tests[testCase](test, common); - } -}; diff --git a/test/unit/sanitizer/search.js b/test/unit/sanitizer/search.js index 0d44103d..52d4c180 100644 --- a/test/unit/sanitizer/search.js +++ b/test/unit/sanitizer/search.js @@ -83,6 +83,10 @@ module.exports.tests.sanitize = function(test, common) { called_sanitizers.push('_categories'); return { errors: [], warnings: [] }; }, + '../sanitizer/_debug': function() { + called_sanitizers.push('_debug'); + return { errors: [], warnings: [] }; + } }); var expected_sanitizers = [ @@ -98,7 +102,8 @@ module.exports.tests.sanitize = function(test, common) { '_flag_bool', '_geo_search', '_boundary_country', - '_categories' + '_categories', + '_debug' ]; var req = {};