Fix context returned in JSON error (had null bytes).

Update status test cases to match new API.
This commit is contained in:
Daniel Patterson 2016-04-01 10:42:42 -07:00 committed by Patrick Niklaus
parent 89d56e1cd1
commit 2cf19010e3
2 changed files with 24 additions and 21 deletions

View File

@ -39,29 +39,29 @@ Feature: Status messages
Given the node locations
| node | lat | lon |
| a | 1.00 | 1.00 |
| b | 1.01 | 1.00 |
| b | 2.00 | 1.00 |
And the ways
| nodes |
| ab |
When I route I should get
| request | status | message |
| viaroute?loc=1,1&loc=1.01,1 | 200 | |
| nonsense | 400 | Service not found |
| nonsense?loc=1,1&loc=1.01,1 | 400 | Service not found |
| | 400 | Query string malformed close to position 0 |
| / | 400 | Query string malformed close to position 0 |
| ? | 400 | Query string malformed close to position 0 |
| viaroute?loc= | 400 | Query string malformed close to position 9 |
| viaroute?loc=1 | 400 | Query string malformed close to position 9 |
| viaroute?loc=1,1 | 400 | Invalid coordinates |
| viaroute?loc=1,1,1 | 400 | Query string malformed close to position 17 |
| viaroute?loc=x | 400 | Query string malformed close to position 9 |
| viaroute?loc=x,y | 400 | Query string malformed close to position 9 |
| viaroute?loc=1,1&loc= | 400 | Query string malformed close to position 17 |
| viaroute?loc=1,1&loc=1 | 400 | Query string malformed close to position 17 |
| viaroute?loc=1,1&loc=1,1 | 200 | |
| viaroute?loc=1,1&loc=1,1,1 | 400 | Query string malformed close to position 25 |
| viaroute?loc=1,1&loc=x | 400 | Query string malformed close to position 17 |
| viaroute?loc=1,1&loc=x,y | 400 | Query string malformed close to position 17 |
| request | status | message |
| route/v1/driving/1,1;1,2 | 200 | |
| nonsense | 400 | URL string malformed close to position 0: "/no" |
| nonsense/v1/driving/1,1;1,2 | 400 | Service nonsense not found! |
| | 400 | URL string malformed close to position 0: "/" |
| / | 400 | URL string malformed close to position 0: "//" |
| ? | 400 | URL string malformed close to position 0: "/?" |
| route/v1/driving | 400 | URL string malformed close to position 0: "/ro" |
| route/v1/driving/ | 400 | URL string malformed close to position 0: "/ro" |
| route/v1/driving/1 | 400 | Query string malformed close to position 0 |
| route/v1/driving/1,1 | 400 | Number of coordinates needs to be at least two. |
| route/v1/driving/1,1,1 | 400 | Query string malformed close to position 3 |
| route/v1/driving/x | 400 | Query string malformed close to position 0 |
| route/v1/driving/x,y | 400 | Query string malformed close to position 0 |
| route/v1/driving/1,1; | 400 | Query string malformed close to position 3 |
| route/v1/driving/1,1;1 | 400 | Query string malformed close to position 3 |
| route/v1/driving/1,1;1,1,1 | 400 | Query string malformed close to position 7 |
| route/v1/driving/1,1;x | 400 | Query string malformed close to position 3 |
| route/v1/driving/1,1;x,y | 400 | Query string malformed close to position 3 |

View File

@ -99,9 +99,12 @@ void RequestHandler::HandleRequest(const http::request &current_request, http::r
else
{
const auto position = std::distance(request_string.begin(), api_iterator);
const auto context_begin = request_string.begin() + std::max(position - 3UL, 0UL);
BOOST_ASSERT(position >= 0);
const auto context_begin = request_string.begin() + ((position < 3) ? 0 : (position - 3UL));
BOOST_ASSERT(context_begin >= request_string.begin());
const auto context_end =
request_string.begin() + std::min(position + 3UL, request_string.size());
BOOST_ASSERT(context_end <= request_string.end());
std::string context(context_begin, context_end);
current_reply.status = http::reply::bad_request;