diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index 2696a4c22..d7ce19d2a 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -1182,10 +1182,10 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo &args, if (source->IsUint32()) { size_t source_value = static_cast(source->NumberValue()); - if (source_value > params->coordinates.size()) + if (source_value >= params->coordinates.size()) { Nan::ThrowError( - "Source indices must be less than or equal to the number of coordinates"); + "Source indices must be less than the number of coordinates"); return table_parameters_ptr(); } @@ -1221,9 +1221,9 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo &args, if (destination->IsUint32()) { size_t destination_value = static_cast(destination->NumberValue()); - if (destination_value > params->coordinates.size()) + if (destination_value >= params->coordinates.size()) { - Nan::ThrowError("Destination indices must be less than or equal to the number " + Nan::ThrowError("Destination indices must be less than the number " "of coordinates"); return table_parameters_ptr(); } diff --git a/test/nodejs/table.js b/test/nodejs/table.js index 7f7fea006..f4f0e6312 100644 --- a/test/nodejs/table.js +++ b/test/nodejs/table.js @@ -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]; diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index 42a4284b2..7d7d196db 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -108,6 +108,8 @@ BOOST_AUTO_TEST_CASE(invalid_table_urls) BOOST_CHECK_EQUAL( testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=-1"), 28UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=2"), 7UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=2"), 7UL); } BOOST_AUTO_TEST_CASE(valid_route_hint)