Browse Source

Merge pull request #140 from pelias/details-flag

Details param not working as expected
pull/141/head
Diana Shkolnikov 10 years ago
parent
commit
542a93c00b
  1. 16
      sanitiser/_details.js
  2. 4
      test/unit/sanitiser/reverse.js
  3. 4
      test/unit/sanitiser/search.js

16
sanitiser/_details.js

@ -18,13 +18,7 @@ function sanitize( req, default_value ){
} }
if (params.details !== undefined) { if (params.details !== undefined) {
var details = params.details; clean.details = isTruthy(params.details);
if (typeof params.details === 'string') {
details = params.details === 'true';
}
clean.details = details === true || details === 1;
} else { } else {
clean.details = default_value; clean.details = default_value;
} }
@ -35,5 +29,13 @@ function sanitize( req, default_value ){
} }
function isTruthy(val) {
if (typeof val === 'string') {
return ['true', '1', 'yes', 'y'].indexOf(val) !== -1;
}
return val === 1 || val === true;
}
// export function // export function
module.exports = sanitize; module.exports = sanitize;

4
test/unit/sanitiser/reverse.js

@ -137,7 +137,7 @@ module.exports.tests.sanitize_details = function(test, common) {
}); });
}); });
var valid_values = [true, 'true', 1]; var valid_values = [true, 'true', 1, '1', 'yes', 'y'];
valid_values.forEach(function(details) { valid_values.forEach(function(details) {
test('valid details param ' + details, function(t) { test('valid details param ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){ sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
@ -154,7 +154,7 @@ module.exports.tests.sanitize_details = function(test, common) {
}); });
}); });
var valid_false_values = ['false', false, 0]; var valid_false_values = ['false', false, 0, '0', 'no', 'n'];
valid_false_values.forEach(function(details) { valid_false_values.forEach(function(details) {
test('test setting false explicitly ' + details, function(t) { test('test setting false explicitly ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){ sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){

4
test/unit/sanitiser/search.js

@ -278,7 +278,7 @@ module.exports.tests.sanitize_details = function(test, common) {
}); });
}); });
var valid_values = ['true', true, 1]; var valid_values = ['true', true, 1, '1', 'yes', 'y'];
valid_values.forEach(function(details) { valid_values.forEach(function(details) {
test('valid details param ' + details, function(t) { test('valid details param ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){ sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
@ -288,7 +288,7 @@ module.exports.tests.sanitize_details = function(test, common) {
}); });
}); });
var valid_false_values = ['false', false, 0]; var valid_false_values = ['false', false, 0, '0', 'no', 'n'];
valid_false_values.forEach(function(details) { valid_false_values.forEach(function(details) {
test('test setting false explicitly ' + details, function(t) { test('test setting false explicitly ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){ sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){

Loading…
Cancel
Save