|
@@ -372,6 +372,8 @@ list_match([E|Tail], [E|TailMatch], Binds) ->
|
|
%% unless V was already defined and E isn't identical to the previous value.
|
|
%% unless V was already defined and E isn't identical to the previous value.
|
|
list_match([E|Tail], [V|TailMatch], Binds) when is_atom(V) ->
|
|
list_match([E|Tail], [V|TailMatch], Binds) when is_atom(V) ->
|
|
case Binds of
|
|
case Binds of
|
|
|
|
+ %% @todo This isn't right, the constraint must be applied FIRST
|
|
|
|
+ %% otherwise we can't check for example ints in both host/path.
|
|
#{V := E} ->
|
|
#{V := E} ->
|
|
list_match(Tail, TailMatch, Binds);
|
|
list_match(Tail, TailMatch, Binds);
|
|
#{V := _} ->
|
|
#{V := _} ->
|
|
@@ -514,7 +516,9 @@ match_test_() ->
|
|
{<<"erlang.fr">>, '_',
|
|
{<<"erlang.fr">>, '_',
|
|
{ok, match_erlang_ext, [], #{ext => <<"fr">>}}},
|
|
{ok, match_erlang_ext, [], #{ext => <<"fr">>}}},
|
|
{<<"any">>, <<"/users/444/friends">>,
|
|
{<<"any">>, <<"/users/444/friends">>,
|
|
- {ok, match_users_friends, [], #{id => <<"444">>}}}
|
|
|
|
|
|
+ {ok, match_users_friends, [], #{id => <<"444">>}}},
|
|
|
|
+ {<<"any">>, <<"/users//friends">>,
|
|
|
|
+ {ok, match_users_friends, [], #{id => <<>>}}}
|
|
],
|
|
],
|
|
[{lists:flatten(io_lib:format("~p, ~p", [H, P])), fun() ->
|
|
[{lists:flatten(io_lib:format("~p, ~p", [H, P])), fun() ->
|
|
{ok, Handler, Opts, Binds, undefined, undefined}
|
|
{ok, Handler, Opts, Binds, undefined, undefined}
|
|
@@ -549,14 +553,20 @@ match_info_test_() ->
|
|
end} || {H, P, R} <- Tests].
|
|
end} || {H, P, R} <- Tests].
|
|
|
|
|
|
match_constraints_test() ->
|
|
match_constraints_test() ->
|
|
- Dispatch = [{'_', [],
|
|
|
|
|
|
+ Dispatch0 = [{'_', [],
|
|
[{[<<"path">>, value], [{value, int}], match, []}]}],
|
|
[{[<<"path">>, value], [{value, int}], match, []}]}],
|
|
- {ok, _, [], #{value := 123}, _, _} = match(Dispatch,
|
|
|
|
|
|
+ {ok, _, [], #{value := 123}, _, _} = match(Dispatch0,
|
|
<<"ninenines.eu">>, <<"/path/123">>),
|
|
<<"ninenines.eu">>, <<"/path/123">>),
|
|
- {ok, _, [], #{value := 123}, _, _} = match(Dispatch,
|
|
|
|
|
|
+ {ok, _, [], #{value := 123}, _, _} = match(Dispatch0,
|
|
<<"ninenines.eu">>, <<"/path/123/">>),
|
|
<<"ninenines.eu">>, <<"/path/123/">>),
|
|
- {error, notfound, path} = match(Dispatch,
|
|
|
|
|
|
+ {error, notfound, path} = match(Dispatch0,
|
|
<<"ninenines.eu">>, <<"/path/NaN/">>),
|
|
<<"ninenines.eu">>, <<"/path/NaN/">>),
|
|
|
|
+ Dispatch1 = [{'_', [],
|
|
|
|
+ [{[<<"path">>, value, <<"more">>], [{value, nonempty}], match, []}]}],
|
|
|
|
+ {ok, _, [], #{value := <<"something">>}, _, _} = match(Dispatch1,
|
|
|
|
+ <<"ninenines.eu">>, <<"/path/something/more">>),
|
|
|
|
+ {error, notfound, path} = match(Dispatch1,
|
|
|
|
+ <<"ninenines.eu">>, <<"/path//more">>),
|
|
Dispatch2 = [{'_', [], [{[<<"path">>, username],
|
|
Dispatch2 = [{'_', [], [{[<<"path">>, username],
|
|
[{username, fun(_, Value) ->
|
|
[{username, fun(_, Value) ->
|
|
case cowboy_bstr:to_lower(Value) of
|
|
case cowboy_bstr:to_lower(Value) of
|