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

Merge pull request #39452 from rolandasb/fix-nil-encrypted-cookie-value

Fix nil encrypted/signed cookie value when value is stored as `false`
This commit is contained in:
Eugene Kenny 2020-05-28 08:49:45 +01:00 committed by GitHub
commit f3f86be7b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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