1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix nil signed/encrypted cookie value when value is stored as false

This commit is contained in:
Rolandas Barysas 2020-05-27 20:14:22 +03:00 committed by Eugene Kenny
parent 9e73208f6d
commit 29d59c4823
2 changed files with 21 additions and 1 deletions

View file

@ -472,7 +472,13 @@ module ActionDispatch
def [](name)
if data = @parent_jar[name.to_s]
parse(name, data, purpose: "cookie.#{name}") || parse(name, data)
result = parse(name, data, purpose: "cookie.#{name}")
if result.nil?
parse(name, data)
else
result
end
end
end

View file

@ -1282,6 +1282,20 @@ class CookiesTest < ActionController::TestCase
end
end
def test_signed_cookie_with_false_value_and_metadata
request.env["action_dispatch.use_cookies_with_metadata"] = true
cookies.signed[:foo] = false
assert_equal false, cookies.signed[:foo]
end
def test_encrypted_cookie_with_false_value_and_metadata
request.env["action_dispatch.use_cookies_with_metadata"] = true
cookies.encrypted[:foo] = false
assert_equal false, cookies.encrypted[:foo]
end
def test_purpose_metadata_for_encrypted_cookies
get :encrypted_discount_and_user_id_cookie