aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Perret <[email protected]>2017-12-01 17:25:17 +0100
committerLoïc Hoguin <[email protected]>2018-03-05 15:13:42 +0100
commitecfcaa12fb2f1aa1226e9329e96cb4ecedbc1bc3 (patch)
treefd9039271a76e7228b6e8ad033e8de89618201fd
parentca3b4d8d1b194d5dd4f2d452eb7bd88932e6617a (diff)
downloadcowlib-ecfcaa12fb2f1aa1226e9329e96cb4ecedbc1bc3.tar.gz
cowlib-ecfcaa12fb2f1aa1226e9329e96cb4ecedbc1bc3.tar.bz2
cowlib-ecfcaa12fb2f1aa1226e9329e96cb4ecedbc1bc3.zip
Allow cookies without a value
Some cookies are seen in the wild consisting of just a name, without even a "=" char. This allows parsing them as if they were written "foo=", that is with an empty value. Commit amended to add a few more test cases.
-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.