aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_dispatcher.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-07-20 22:07:35 +0200
committerLoïc Hoguin <[email protected]>2011-07-20 22:07:35 +0200
commit503a0c76628236ed14a22802c2ebd523148ab0e3 (patch)
treeea156e912b8ec38421e4ec36575b7558635118a9 /src/cowboy_dispatcher.erl
parentfa20273b37255a987e90fc68bea22cd29e404aaf (diff)
downloadcowboy-503a0c76628236ed14a22802c2ebd523148ab0e3.tar.gz
cowboy-503a0c76628236ed14a22802c2ebd523148ab0e3.tar.bz2
cowboy-503a0c76628236ed14a22802c2ebd523148ab0e3.zip
URL decode paths
This fixes issue #33.
Diffstat (limited to 'src/cowboy_dispatcher.erl')
-rw-r--r--src/cowboy_dispatcher.erl10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/cowboy_dispatcher.erl b/src/cowboy_dispatcher.erl
index 718b13e..c402e01 100644
--- a/src/cowboy_dispatcher.erl
+++ b/src/cowboy_dispatcher.erl
@@ -56,10 +56,11 @@ split_path(Path) ->
-spec do_split_path(binary(), <<_:8>>) -> path_tokens().
do_split_path(RawPath, Separator) ->
- case binary:split(RawPath, Separator, [global, trim]) of
+ EncodedPath = case binary:split(RawPath, Separator, [global, trim]) of
[<<>>|Path] -> Path;
Path -> Path
- end.
+ end,
+ [quoted:from_url(Token) || Token <- EncodedPath].
%% @doc Match hostname tokens and path tokens against dispatch rules.
%%
@@ -214,7 +215,10 @@ split_path_test_() ->
{<<"/users?a">>, [<<"users">>], <<"/users">>, <<"a">>},
{<<"/users/42/friends?a=b&c=d&e=notsure?whatever">>,
[<<"users">>, <<"42">>, <<"friends">>],
- <<"/users/42/friends">>, <<"a=b&c=d&e=notsure?whatever">>}
+ <<"/users/42/friends">>, <<"a=b&c=d&e=notsure?whatever">>},
+ {<<"/users/a+b/c%21d?e+f=g+h">>,
+ [<<"users">>, <<"a b">>, <<"c!d">>],
+ <<"/users/a+b/c%21d">>, <<"e+f=g+h">>}
],
[{P, fun() -> {R, RawP, Qs} = split_path(P) end}
|| {P, R, RawP, Qs} <- Tests].