Browse Source

de-dupe as part of sanitizing

pull/34/head
Harish Krishna 10 years ago
parent
commit
5e42b4ac0c
  1. 5
      sanitiser/_id.js
  2. 11
      test/unit/sanitiser/get.js

5
sanitiser/_id.js

@ -29,6 +29,11 @@ function sanitize( req ){
req.clean.ids = [];
params.ids = Array.isArray(params.id) ? params.id : [params.id];
// de-dupe
params.ids = params.ids.filter(function(item, pos) {
return params.ids.indexOf(item) == pos;
});
for (var i=0; i<params.ids.length; i++) {
var thisparam = params.ids[i];

11
test/unit/sanitiser/get.js

@ -102,6 +102,17 @@ module.exports.tests.sanitize_ids = function(test, common) {
});
};
module.exports.tests.de_dupe = function(test, common) {
var expected = { ids: [ { id: '1', type: 'geoname' }, { id: '2', type: 'osmnode' } ] };
test('duplicate ids', function(t) {
sanitize( { id: ['geoname:1', 'osmnode:2', 'geoname:1'] }, function( err, clean ){
t.equal(err, undefined, 'no error' );
t.deepEqual(clean, expected, 'clean set correctly');
t.end();
});
});
};
module.exports.tests.invalid_params = function(test, common) {
test('invalid params', function(t) {
sanitize( undefined, function( err, clean ){

Loading…
Cancel
Save