Просмотр исходного кода

Fix handling of default values in cookie options

Previously, an error would be raised when explicitly passing a default
value for either “http_only” or “secure” option.
Krzysztof Jurewicz 10 лет назад
Родитель
Сommit
f9a630232f
1 измененных файлов с 8 добавлено и 0 удалено
  1. 8 0
      src/cow_cookie.erl

+ 8 - 0
src/cow_cookie.erl

@@ -197,10 +197,12 @@ setcookie(Name, Value, Opts) ->
 	end,
 	SecureBin = case lists:keyfind(secure, 1, Opts) of
 		false -> <<>>;
+		{_, false} -> <<>>;
 		{_, true} -> <<"; Secure">>
 	end,
 	HttpOnlyBin = case lists:keyfind(http_only, 1, Opts) of
 		false -> <<>>;
+		{_, false} -> <<>>;
 		{_, true} -> <<"; HttpOnly">>
 	end,
 	[Name, <<"=">>, Value, <<"; Version=1">>,
@@ -218,6 +220,12 @@ setcookie_test_() ->
 			[{path, <<"/acme">>}],
 			<<"Customer=WILE_E_COYOTE; Version=1; Path=/acme">>},
 		{<<"Customer">>, <<"WILE_E_COYOTE">>,
+			[{secure, true}],
+			<<"Customer=WILE_E_COYOTE; Version=1; Secure">>},
+		{<<"Customer">>, <<"WILE_E_COYOTE">>,
+			[{secure, false}, {http_only, false}],
+			<<"Customer=WILE_E_COYOTE; Version=1">>},
+		{<<"Customer">>, <<"WILE_E_COYOTE">>,
 			[{path, <<"/acme">>}, {badoption, <<"negatory">>}],
 			<<"Customer=WILE_E_COYOTE; Version=1; Path=/acme">>}
 	],