Browse Source

Error on multiple ids parameters instead of warning

pull/273/head
Julian Simioni 9 years ago
parent
commit
cd63209085
  1. 10
      sanitiser/_ids.js
  2. 4
      test/unit/sanitiser/place.js

10
sanitiser/_ids.js

@ -18,11 +18,13 @@ function sanitize( raw, clean ){
// 'raw.ids' can be an array if ids is specified multiple times // 'raw.ids' can be an array if ids is specified multiple times
// see https://github.com/pelias/api/issues/272 // see https://github.com/pelias/api/issues/272
var rawIdsString;
if (check.array( raw.ids )) { if (check.array( raw.ids )) {
rawIdsString = raw.ids[0]; messages.errors.push( '`ids` parameter specified multiple times.' );
messages.warnings.push( '`ids` parameter specified multiple times. Using first value.' ); return messages;
} else if (check.unemptyString( raw.ids )) { }
var rawIdsString;
if (check.unemptyString( raw.ids )) {
rawIdsString = raw.ids; rawIdsString = raw.ids;
} else { } else {
rawIdsString = ''; rawIdsString = '';

4
test/unit/sanitiser/place.js

@ -113,8 +113,8 @@ module.exports.tests.array_of_ids = function(test, common) {
test('array of ids sent by queryparser', function(t) { test('array of ids sent by queryparser', function(t) {
var req = { query: { ids: ['geoname:2', 'oswmay:4'] } }; var req = { query: { ids: ['geoname:2', 'oswmay:4'] } };
sanitize(req, function() { sanitize(req, function() {
t.deepEqual( req.warnings, ['`ids` parameter specified multiple times. Using first value.'], 'warning sent' ); t.deepEqual( req.errors, ['`ids` parameter specified multiple times.'], 'error sent' );
t.deepEqual( req.clean.ids, [{ id: '2', type: 'geoname' }], 'only first value used in clean' ); t.deepEqual( req.clean.ids, undefined, 'response is empty due to error' );
t.end(); t.end();
}); });
}); });

Loading…
Cancel
Save