Validate source/destination indices correctly in nodejs support (#5595)

* validate source/destination indices correctly

Co-authored-by: Denis Chapligin <denis.chaplygin@wolt.com>
Co-authored-by: Daniel Patterson <danpat@danpat.net>
This commit is contained in:
Karen Shea
2021-01-28 15:02:01 +01:00
committed by GitHub
parent 960269f95a
commit a613375460
4 changed files with 22 additions and 8 deletions
+9 -3
View File
@@ -130,7 +130,7 @@ tables.forEach(function(annotation) {
});
test('table: ' + annotation + ' throws on invalid arguments', function(assert) {
assert.plan(15);
assert.plan(17);
var osrm = new OSRM(data_path);
var options = {annotations: [annotation.slice(0,-1)]};
assert.throws(function() { osrm.table(options); },
@@ -157,10 +157,13 @@ tables.forEach(function(annotation) {
/Sources must be an array of indices \(or undefined\)/);
options.sources = [0, 4];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Source indices must be less than or equal to the number of coordinates/);
/Source indices must be less than the number of coordinates/);
options.sources = [0.3, 1.1];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Source must be an integer/);
options.sources = [0, 1, 2];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Source indices must be less than the number of coordinates/);
options.destinations = true;
delete options.sources;
@@ -168,10 +171,13 @@ tables.forEach(function(annotation) {
/Destinations must be an array of indices \(or undefined\)/);
options.destinations = [0, 4];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Destination indices must be less than or equal to the number of coordinates/);
/Destination indices must be less than the number of coordinates/);
options.destinations = [0.3, 1.1];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Destination must be an integer/);
options.destinations = [0, 4];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Destination indices must be less than the number of coordinates/);
// does not throw: the following two have been changed in OSRM v5
options.sources = [0, 1];