aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cow_cookie.erl20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/cow_cookie.erl b/src/cow_cookie.erl
index 7ee067a..60bf299 100644
--- a/src/cow_cookie.erl
+++ b/src/cow_cookie.erl
@@ -53,16 +53,16 @@ skip_cookie(<< $;, Rest/binary >>, Acc) ->
skip_cookie(<< _, Rest/binary >>, Acc) ->
skip_cookie(Rest, Acc).
-parse_cookie_name(<<>>, _, _) ->
- error(badarg);
+parse_cookie_name(<<>>, Acc, Name) ->
+ lists:reverse([{Name, <<>>}|Acc]);
parse_cookie_name(<< $=, _/binary >>, _, <<>>) ->
error(badarg);
parse_cookie_name(<< $=, Rest/binary >>, Acc, Name) ->
parse_cookie_value(Rest, Acc, Name, <<>>);
parse_cookie_name(<< $,, _/binary >>, _, _) ->
error(badarg);
-parse_cookie_name(<< $;, _/binary >>, _, _) ->
- error(badarg);
+parse_cookie_name(<< $;, Rest/binary >>, Acc, Name) ->
+ parse_cookie(Rest, [{Name, <<>>}|Acc]);
parse_cookie_name(<< $\s, _/binary >>, _, _) ->
error(badarg);
parse_cookie_name(<< $\t, _/binary >>, _, _) ->
@@ -151,8 +151,14 @@ parse_cookie_test_() ->
{<<"foo=;bar=">>, [{<<"foo">>, <<>>}, {<<"bar">>, <<>>}]},
{<<"foo=\\\";;bar=good ">>,
[{<<"foo">>, <<"\\\"">>}, {<<"bar">>, <<"good">>}]},
+ {<<"foo=\"\\\";bar=good">>,
+ [{<<"foo">>, <<"\"\\\"">>}, {<<"bar">>, <<"good">>}]},
{<<>>, []}, %% Flash player.
- {<<"foo=bar , baz=wibble ">>, [{<<"foo">>, <<"bar , baz=wibble">>}]}
+ {<<"foo=bar , baz=wibble ">>, [{<<"foo">>, <<"bar , baz=wibble">>}]},
+ %% Technically invalid, but seen in the wild
+ {<<"foo">>, [{<<"foo">>, <<>>}]},
+ {<<"foo;">>, [{<<"foo">>, <<>>}]},
+ {<<"bar;foo=1">>, [{<<"bar">>, <<"">>}, {<<"foo">>, <<"1">>}]}
],
[{V, fun() -> R = parse_cookie(V) end} || {V, R} <- Tests].
@@ -160,9 +166,7 @@ parse_cookie_error_test_() ->
%% Value.
Tests = [
<<"=">>,
- <<" foo ; bar ">>,
- <<"foo=\\\";;bar ">>,
- <<"foo=\"\\\";bar">>
+ <<"foo ">>
],
[{V, fun() -> {'EXIT', {badarg, _}} = (catch parse_cookie(V)) end} || V <- Tests].
-endif.