mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
fix match_qs with constraints when key is not present
This commit is contained in:
parent
906a7ffc3c
commit
8f3f21225d
3 changed files with 8 additions and 1 deletions
|
@ -1006,7 +1006,12 @@ filter([], Map, Errors) ->
|
||||||
_ -> {error, Errors}
|
_ -> {error, Errors}
|
||||||
end;
|
end;
|
||||||
filter([{Key, Constraints}|Tail], Map, Errors) ->
|
filter([{Key, Constraints}|Tail], Map, Errors) ->
|
||||||
filter_constraints(Tail, Map, Errors, Key, maps:get(Key, Map), Constraints);
|
case maps:find(Key, Map) of
|
||||||
|
{ok, Value} ->
|
||||||
|
filter_constraints(Tail, Map, Errors, Key, Value, Constraints);
|
||||||
|
error ->
|
||||||
|
filter(Tail, Map, Errors#{Key => required})
|
||||||
|
end;
|
||||||
filter([{Key, Constraints, Default}|Tail], Map, Errors) ->
|
filter([{Key, Constraints, Default}|Tail], Map, Errors) ->
|
||||||
case maps:find(Key, Map) of
|
case maps:find(Key, Map) of
|
||||||
{ok, Value} ->
|
{ok, Value} ->
|
||||||
|
|
|
@ -86,6 +86,7 @@ echo(<<"match">>, Req, Opts) ->
|
||||||
Fields = [binary_to_atom(F, latin1) || F <- Fields0],
|
Fields = [binary_to_atom(F, latin1) || F <- Fields0],
|
||||||
Value = case Type of
|
Value = case Type of
|
||||||
<<"qs">> -> cowboy_req:match_qs(Fields, Req);
|
<<"qs">> -> cowboy_req:match_qs(Fields, Req);
|
||||||
|
<<"qs_with_constraints">> -> cowboy_req:match_qs([{id, integer}], Req);
|
||||||
<<"cookies">> -> cowboy_req:match_cookies(Fields, Req);
|
<<"cookies">> -> cowboy_req:match_cookies(Fields, Req);
|
||||||
<<"body_qs">> ->
|
<<"body_qs">> ->
|
||||||
%% Note that the Req should not be discarded but for the
|
%% Note that the Req should not be discarded but for the
|
||||||
|
|
|
@ -265,6 +265,7 @@ match_qs(Config) ->
|
||||||
end,
|
end,
|
||||||
%% Ensure match errors result in a 400 response.
|
%% Ensure match errors result in a 400 response.
|
||||||
{400, _, _} = do_get("/match/qs/a/c?a=b", [], Config),
|
{400, _, _} = do_get("/match/qs/a/c?a=b", [], Config),
|
||||||
|
{400, _, _} = do_get("/match/qs_with_constraints", [], Config),
|
||||||
%% This function is tested more extensively through unit tests.
|
%% This function is tested more extensively through unit tests.
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue