Skip to content

Commit

Permalink
Treat invalid JSON as bad request in the rest interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-carlborg committed Jul 25, 2016
1 parent 9e08928 commit eb5ef76
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions source/vibe/web/rest.d
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,12 @@ private HTTPServerRequestDelegate jsonMethodHandler(alias Func, size_t ridx, T)(
if (auto pv = fieldname in req.query)
v = fromRestString!PT(*pv);
} else static if (sparam.kind == ParameterKind.body_) {
if (auto pv = fieldname in req.json)
v = deserializeJson!PT(*pv);
if (auto pv = fieldname in req.json) {
try
v = deserializeJson!PT(*pv);
catch (JSONException e)
enforceBadRequest(false, e.msg);
}
} else static if (sparam.kind == ParameterKind.header) {
if (auto pv = fieldname in req.headers)
v = fromRestString!PT(*pv);
Expand Down Expand Up @@ -1506,6 +1510,8 @@ private {
else return deserializeJson!T(parseJson(value));
} catch (ConvException e) {
throw new HTTPStatusException(HTTPStatus.badRequest, e.msg);
} catch (JSONException e) {
throw new HTTPStatusException(HTTPStatus.badRequest, e.msg);
}
}
}
Expand Down

0 comments on commit eb5ef76

Please sign in to comment.