diff options
author | Loïc Hoguin <[email protected]> | 2014-05-18 18:46:39 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-05-18 18:46:39 +0200 |
commit | 3ffadd8f45370499fbfa5ff994675447c51e3912 (patch) | |
tree | 95c4489a2977cb60520ff37d03385e1c27153530 /src | |
parent | f58340a0044856bb508df03cfe94cf79308380a2 (diff) | |
download | cowlib-3ffadd8f45370499fbfa5ff994675447c51e3912.tar.gz cowlib-3ffadd8f45370499fbfa5ff994675447c51e3912.tar.bz2 cowlib-3ffadd8f45370499fbfa5ff994675447c51e3912.zip |
Accept commas as part of cookie values
Google Analytics has been observed to set cookie values containing
commas. We therefore need to accept them for interoperability.
Diffstat (limited to 'src')
-rw-r--r-- | src/cow_cookie.erl | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/cow_cookie.erl b/src/cow_cookie.erl index 895c93c..6db89be 100644 --- a/src/cow_cookie.erl +++ b/src/cow_cookie.erl @@ -80,8 +80,6 @@ parse_cookie_name(<< C, Rest/binary >>, Acc, Name) -> parse_cookie_value(<<>>, Acc, Name, Value) -> lists:reverse([{Name, parse_cookie_trim(Value)}|Acc]); -parse_cookie_value(<< $,, Rest/binary >>, Acc, Name, Value) -> - parse_cookie(Rest, [{Name, parse_cookie_trim(Value)}|Acc]); parse_cookie_value(<< $;, Rest/binary >>, Acc, Name, Value) -> parse_cookie(Rest, [{Name, parse_cookie_trim(Value)}|Acc]); parse_cookie_value(<< $\t, _/binary >>, _, _, _) -> @@ -130,6 +128,24 @@ parse_cookie_test_() -> %% Space in value. {<<"foo=Thu Jul 11 2013 15:38:43 GMT+0400 (MSK)">>, [{<<"foo">>, <<"Thu Jul 11 2013 15:38:43 GMT+0400 (MSK)">>}]}, + %% Comma in value. Google Analytics sets that kind of cookies. + {<<"refk=sOUZDzq2w2; sk=B602064E0139D842D620C7569640DBB4C81C45080651" + "9CC124EF794863E10E80; __utma=64249653.825741573.1380181332.1400" + "015657.1400019557.703; __utmb=64249653.1.10.1400019557; __utmc=" + "64249653; __utmz=64249653.1400019557.703.13.utmcsr=bluesky.chic" + "agotribune.com|utmccn=(referral)|utmcmd=referral|utmcct=/origin" + "als/chi-12-indispensable-digital-tools-bsi,0,0.storygallery">>, [ + {<<"refk">>, <<"sOUZDzq2w2">>}, + {<<"sk">>, <<"B602064E0139D842D620C7569640DBB4C81C45080651" + "9CC124EF794863E10E80">>}, + {<<"__utma">>, <<"64249653.825741573.1380181332.1400" + "015657.1400019557.703">>}, + {<<"__utmb">>, <<"64249653.1.10.1400019557">>}, + {<<"__utmc">>, <<"64249653">>}, + {<<"__utmz">>, <<"64249653.1400019557.703.13.utmcsr=bluesky.chic" + "agotribune.com|utmccn=(referral)|utmcmd=referral|utmcct=/origin" + "als/chi-12-indispensable-digital-tools-bsi,0,0.storygallery">>} + ]}, %% Potential edge cases (initially from Mochiweb). {<<"foo=\\x">>, [{<<"foo">>, <<"\\x">>}]}, {<<"=">>, {error, badarg}}, @@ -140,8 +156,7 @@ parse_cookie_test_() -> [{<<"foo">>, <<"\\\"">>}, {<<"bar">>, <<"good">>}]}, {<<"foo=\"\\\";bar">>, {error, badarg}}, {<<>>, []}, - {<<"foo=bar , baz=wibble ">>, - [{<<"foo">>, <<"bar">>}, {<<"baz">>, <<"wibble">>}]} + {<<"foo=bar , baz=wibble ">>, [{<<"foo">>, <<"bar , baz=wibble">>}]} ], [{V, fun() -> R = parse_cookie(V) end} || {V, R} <- Tests]. -endif. |