aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/cookies.rb
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2015-09-01 04:20:32 -0400
committereileencodes <eileencodes@gmail.com>2015-09-01 08:42:30 -0400
commit75a121a2c5470e2bfc7347567a8dc5f89b3812ca (patch)
tree4dd77673d13ad8efcb44e953d0a513802c1139a5 /actionpack/lib/action_dispatch/middleware/cookies.rb
parent8ce0fdb5c412a5083dff3ecb863e86c1853651d7 (diff)
downloadrails-75a121a2c5470e2bfc7347567a8dc5f89b3812ca.tar.gz
rails-75a121a2c5470e2bfc7347567a8dc5f89b3812ca.tar.bz2
rails-75a121a2c5470e2bfc7347567a8dc5f89b3812ca.zip
Fix bug where cookies mutated by request were not persisted
With changes made in 8363b8 and ae29142 cookies that are mutated on the request like `cookies.signed = x` were not retained in subsequent tests, breaking cookie authentiation in controller tests. The test added demonstrates the issue. The reason we need to select from non-deleted cookies is because without checking the `@delete_cookies` the `cookie_jar` `@cookies` will send the wrong cookies to be updated. The code must check for `@deleted_cookies` before sending an `#update` with the requests cookie_jar cookies. This follows how the cookie_jar cookies from the request were updated before these changes.
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/cookies.rb')
-rw-r--r--actionpack/lib/action_dispatch/middleware/cookies.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index 6d0387cf74..f958a88e4b 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -319,6 +319,13 @@ module ActionDispatch
self
end
+ def update_cookies_from_jar
+ request_jar = @request.cookie_jar.instance_variable_get(:@cookies)
+ set_cookies = request_jar.reject { |k,_| @delete_cookies.key?(k) }
+
+ @cookies.update set_cookies if set_cookies
+ end
+
def to_header
@cookies.map { |k,v| "#{k}=#{v}" }.join ';'
end