Skip to content

Commit

Permalink
Only allow _body and _json as valid parameter names for Json types
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Nov 30, 2017
1 parent 2a42a31 commit e44ffef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/vibe.web.web/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Service {
@noRoute void getFoo(HTTPServerResponse res) { res.writeBody("oops"); }
void getBar(HTTPServerResponse res) { res.writeBody("ok"); }
// you can work with Json objects directly
auto postJson(Json json) { return json; }
auto postJson(Json _json) { return _json; }
}

shared static this()
Expand Down
2 changes: 2 additions & 0 deletions web/vibe/web/web.d
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,8 @@ private void handleRequest(string M, alias overload, C, ERROR...)(HTTPServerRequ
else static if (is(PT == HTTPServerRequest) || is(PT == HTTPRequest)) params[i] = req;
else static if (is(PT == HTTPServerResponse) || is(PT == HTTPResponse)) params[i] = res;
else static if (is(PT == Json)) {
import std.algorithm.comparison : among;
static assert(param_names[i].among("_body", "_json", "The Json parameter must be named _body or _json."));
enforceBadRequest(req.json.type != Json.Type.undefined, "Invalid Json passed.");
params[i] = req.json;
}
Expand Down

0 comments on commit e44ffef

Please sign in to comment.