Catch boost bad_numeric_cast exception and let parser return an error

This commit is contained in:
Patrick Niklaus 2016-10-10 17:20:29 +02:00 committed by Patrick Niklaus
parent 14b024e4dc
commit 240a7696da
3 changed files with 28 additions and 19 deletions

View File

@ -48,6 +48,7 @@ Feature: Status messages
When I route I should get
| request | status | message |
| route/v1/driving/1,1;1,2 | 200 | |
| route/v1/driving/-74697224,5.191564 | 400 | Query string malformed close to position 18 |
| nonsense | 400 | URL string malformed close to position 9: "nse" |
| nonsense/v1/driving/1,1;1,2 | 400 | Service nonsense not found! |
| | 400 | URL string malformed close to position 1: "/" |

View File

@ -55,6 +55,11 @@ boost::optional<ParameterT> parseParameters(std::string::iterator &iter,
// iterator to the failing position. Extract the position from the exception ourselves.
iter = failure.first;
}
catch (const boost::numeric::bad_numeric_cast &e)
{
// this can happen if we get bad numeric values in the request, just handle
// as normal parser error
}
return boost::none;
}

View File

@ -35,6 +35,9 @@ template <typename ParameterT> std::size_t testInvalidOptions(std::string option
BOOST_AUTO_TEST_CASE(invalid_route_urls)
{
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("a;3,4"), 0UL);
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("120;3,4"), 3UL);
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("90000000,2;3,4"), 0UL);
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&bla=foo"), 22UL);
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&bearings=foo"),
32UL);