0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 04:30:25 +00:00

Add missing quotes to quoting for cookie values

This commit is contained in:
Loïc Hoguin 2012-12-13 16:54:07 +01:00
parent ea7af4b724
commit 6074ce4a39

View file

@ -845,11 +845,11 @@ cookie_to_iodata(Name, Value, Opts) ->
-spec quote(binary()) -> binary(). -spec quote(binary()) -> binary().
quote(Bin) -> quote(Bin) ->
quote(Bin, <<>>). quote(Bin, << $" >>).
-spec quote(binary(), binary()) -> binary(). -spec quote(binary(), binary()) -> binary().
quote(<<>>, Acc) -> quote(<<>>, Acc) ->
Acc; << Acc/binary, $" >>;
quote(<< $", Rest/bits >>, Acc) -> quote(<< $", Rest/bits >>, Acc) ->
quote(Rest, << Acc/binary, $\\, $" >>); quote(Rest, << Acc/binary, $\\, $" >>);
quote(<< C, Rest/bits >>, Acc) -> quote(<< C, Rest/bits >>, Acc) ->
@ -1160,14 +1160,14 @@ cookie_to_iodata_test_() ->
Tests = [ Tests = [
{<<"Customer">>, <<"WILE_E_COYOTE">>, {<<"Customer">>, <<"WILE_E_COYOTE">>,
[{http_only, true}, {domain, <<"acme.com">>}], [{http_only, true}, {domain, <<"acme.com">>}],
<<"Customer=WILE_E_COYOTE; Version=1; " <<"Customer=\"WILE_E_COYOTE\"; Version=1; "
"Domain=acme.com; HttpOnly">>}, "Domain=\"acme.com\"; HttpOnly">>},
{<<"Customer">>, <<"WILE_E_COYOTE">>, {<<"Customer">>, <<"WILE_E_COYOTE">>,
[{path, <<"/acme">>}], [{path, <<"/acme">>}],
<<"Customer=WILE_E_COYOTE; Version=1; Path=/acme">>}, <<"Customer=\"WILE_E_COYOTE\"; Version=1; Path=\"/acme\"">>},
{<<"Customer">>, <<"WILE_E_COYOTE">>, {<<"Customer">>, <<"WILE_E_COYOTE">>,
[{path, <<"/acme">>}, {badoption, <<"negatory">>}], [{path, <<"/acme">>}, {badoption, <<"negatory">>}],
<<"Customer=WILE_E_COYOTE; Version=1; Path=/acme">>} <<"Customer=\"WILE_E_COYOTE\"; Version=1; Path=\"/acme\"">>}
], ],
[{R, fun() -> R = iolist_to_binary(cookie_to_iodata(N, V, O)) end} [{R, fun() -> R = iolist_to_binary(cookie_to_iodata(N, V, O)) end}
|| {N, V, O, R} <- Tests]. || {N, V, O, R} <- Tests].
@ -1177,7 +1177,7 @@ cookie_to_iodata_max_age_test() ->
binary:split(iolist_to_binary( binary:split(iolist_to_binary(
cookie_to_iodata(N, V, O)), <<";">>, [global]) cookie_to_iodata(N, V, O)), <<";">>, [global])
end, end,
[<<"Customer=WILE_E_COYOTE">>, [<<"Customer=\"WILE_E_COYOTE\"">>,
<<" Version=1">>, <<" Version=1">>,
<<" Expires=", _/binary>>, <<" Expires=", _/binary>>,
<<" Max-Age=111">>, <<" Max-Age=111">>,
@ -1186,7 +1186,7 @@ cookie_to_iodata_max_age_test() ->
case catch F(<<"Customer">>, <<"WILE_E_COYOTE">>, [{max_age, -111}]) of case catch F(<<"Customer">>, <<"WILE_E_COYOTE">>, [{max_age, -111}]) of
{'EXIT', {{case_clause, {max_age, -111}}, _}} -> ok {'EXIT', {{case_clause, {max_age, -111}}, _}} -> ok
end, end,
[<<"Customer=WILE_E_COYOTE">>, [<<"Customer=\"WILE_E_COYOTE\"">>,
<<" Version=1">>, <<" Version=1">>,
<<" Expires=", _/binary>>, <<" Expires=", _/binary>>,
<<" Max-Age=86417">>] = F(<<"Customer">>, <<"WILE_E_COYOTE">>, <<" Max-Age=86417">>] = F(<<"Customer">>, <<"WILE_E_COYOTE">>,