validate source/destination indices correctly
This commit is contained in:
parent
f520379419
commit
d3aad767ec
@ -1182,10 +1182,10 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
|
||||
if (source->IsUint32())
|
||||
{
|
||||
size_t source_value = static_cast<size_t>(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<v8::Value> &args,
|
||||
if (destination->IsUint32())
|
||||
{
|
||||
size_t destination_value = static_cast<size_t>(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();
|
||||
}
|
||||
|
||||
@ -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];
|
||||
|
||||
@ -108,6 +108,8 @@ BOOST_AUTO_TEST_CASE(invalid_table_urls)
|
||||
BOOST_CHECK_EQUAL(
|
||||
testInvalidOptions<TableParameters>("1,2;3,4?annotations=durations&fallback_speed=-1"),
|
||||
28UL);
|
||||
BOOST_CHECK_EQUAL(testInvalidOptions<TableParameters>("1,2;3,4?sources=2"), 7UL);
|
||||
BOOST_CHECK_EQUAL(testInvalidOptions<TableParameters>("1,2;3,4?destinations=2"), 7UL);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(valid_route_hint)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user