0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00

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.
This commit is contained in:
Loïc Hoguin 2011-07-20 17:38:10 +02:00
parent 293cf33702
commit fa20273b37
4 changed files with 13 additions and 4 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
.cowboy_dialyzer.plt .cowboy_dialyzer.plt
.eunit .eunit
deps
doc/*.css doc/*.css
doc/*.html doc/*.html
doc/*.png doc/*.png

View file

@ -5,9 +5,12 @@ REBAR = rebar
all: app all: app
app: app: deps
@$(REBAR) compile @$(REBAR) compile
deps:
@$(REBAR) get-deps
clean: clean:
@$(REBAR) clean @$(REBAR) clean
rm -f test/*.beam rm -f test/*.beam

View file

@ -1,4 +1,8 @@
{cover_enabled, true}. {cover_enabled, true}.
{deps, [
{quoted, "1.0.0",
{git, "git://github.com/klaar/quoted.erl.git", {tag, "1.0.1"}}}
]}.
{erl_opts, [ {erl_opts, [
%% bin_opt_info, %% bin_opt_info,
%% warn_missing_spec, %% warn_missing_spec,

View file

@ -282,8 +282,8 @@ parse_qs(<<>>) ->
parse_qs(Qs) -> parse_qs(Qs) ->
Tokens = binary:split(Qs, <<"&">>, [global, trim]), Tokens = binary:split(Qs, <<"&">>, [global, trim]),
[case binary:split(Token, <<"=">>) of [case binary:split(Token, <<"=">>) of
[Token] -> {Token, true}; [Token] -> {quoted:from_url(Token), true};
[Name, Value] -> {Name, Value} [Name, Value] -> {quoted:from_url(Name), quoted:from_url(Value)}
end || Token <- Tokens]. end || Token <- Tokens].
-spec response_head(http_status(), http_headers(), http_headers()) -> iolist(). -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">>, [{<<"a">>, true}, {<<"b">>, true}]},
{<<"a=b&c&d=e">>, [{<<"a">>, <<"b">>}, {<<"a=b&c&d=e">>, [{<<"a">>, <<"b">>},
{<<"c">>, true}, {<<"d">>, <<"e">>}]}, {<<"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]. [{Qs, fun() -> R = parse_qs(Qs) end} || {Qs, R} <- Tests].