aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-07-20 17:38:10 +0200
committerLoïc Hoguin <[email protected]>2011-07-20 17:38:10 +0200
commitfa20273b37255a987e90fc68bea22cd29e404aaf (patch)
tree5dc08993dbfe24b352ae23084b05fd70ba44aa1c /src
parent293cf33702c8cad471989c1e08ce05323baadaf7 (diff)
downloadcowboy-fa20273b37255a987e90fc68bea22cd29e404aaf.tar.gz
cowboy-fa20273b37255a987e90fc68bea22cd29e404aaf.tar.bz2
cowboy-fa20273b37255a987e90fc68bea22cd29e404aaf.zip
URL decode query strings
Should be good for both GET and POST query strings. This adds https://github.com/klaar/quoted.erl as a dependency. Props to klaar for this code.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http_req.erl7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl
index 7fb69b6..60cdbc3 100644
--- a/src/cowboy_http_req.erl
+++ b/src/cowboy_http_req.erl
@@ -282,8 +282,8 @@ parse_qs(<<>>) ->
parse_qs(Qs) ->
Tokens = binary:split(Qs, <<"&">>, [global, trim]),
[case binary:split(Token, <<"=">>) of
- [Token] -> {Token, true};
- [Name, Value] -> {Name, Value}
+ [Token] -> {quoted:from_url(Token), true};
+ [Name, Value] -> {quoted:from_url(Name), quoted:from_url(Value)}
end || Token <- Tokens].
-spec response_head(http_status(), http_headers(), http_headers()) -> iolist().
@@ -427,7 +427,8 @@ parse_qs_test_() ->
{<<"a&b">>, [{<<"a">>, true}, {<<"b">>, true}]},
{<<"a=b&c&d=e">>, [{<<"a">>, <<"b">>},
{<<"c">>, true}, {<<"d">>, <<"e">>}]},
- {<<"a=b=c=d=e&f=g">>, [{<<"a">>, <<"b=c=d=e">>}, {<<"f">>, <<"g">>}]}
+ {<<"a=b=c=d=e&f=g">>, [{<<"a">>, <<"b=c=d=e">>}, {<<"f">>, <<"g">>}]},
+ {<<"a+b=c+d">>, [{<<"a b">>, <<"c d">>}]}
],
[{Qs, fun() -> R = parse_qs(Qs) end} || {Qs, R} <- Tests].