diff options
author | Matt Bauer <bauer@Mosquito.local> | 2008-12-20 14:37:51 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-12-20 14:37:51 -0600 |
commit | 7b249b67e9df9f375eaad9e6eb41be73338faaa7 (patch) | |
tree | a40d4f8d4e395564cb00afcb4e946114045da117 /actionpack/lib | |
parent | 462c75b60c659d75fafaeb10dd6ba9d4c16b6cb2 (diff) | |
download | rails-7b249b67e9df9f375eaad9e6eb41be73338faaa7.tar.gz rails-7b249b67e9df9f375eaad9e6eb41be73338faaa7.tar.bz2 rails-7b249b67e9df9f375eaad9e6eb41be73338faaa7.zip |
Fix reset_session with lazy cookie stores [#1601 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/session/abstract_store.rb | 18 | ||||
-rw-r--r-- | actionpack/lib/action_controller/session/cookie_store.rb | 12 |
2 files changed, 18 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/session/abstract_store.rb b/actionpack/lib/action_controller/session/abstract_store.rb index d4b185aaa2..bf09fd33c5 100644 --- a/actionpack/lib/action_controller/session/abstract_store.rb +++ b/actionpack/lib/action_controller/session/abstract_store.rb @@ -53,6 +53,10 @@ module ActionController end private + def loaded? + @loaded + end + def load! @id, session = @by.send(:load_session, @env) replace(session) @@ -91,19 +95,23 @@ module ActionController def call(env) session = SessionHash.new(self, env) - original_session = session.dup env[ENV_SESSION_KEY] = session env[ENV_SESSION_OPTIONS_KEY] = @default_options.dup response = @app.call(env) - session = env[ENV_SESSION_KEY] - unless session == original_session + session_data = env[ENV_SESSION_KEY] + if !session_data.is_a?(AbstractStore::SessionHash) || session_data.send(:loaded?) options = env[ENV_SESSION_OPTIONS_KEY] - sid = session.id - unless set_session(env, sid, session.to_hash) + if session_data.is_a?(AbstractStore::SessionHash) + sid = session_data.id + else + sid = generate_sid + end + + unless set_session(env, sid, session_data.to_hash) return response end diff --git a/actionpack/lib/action_controller/session/cookie_store.rb b/actionpack/lib/action_controller/session/cookie_store.rb index ba63f8521f..135bedaf50 100644 --- a/actionpack/lib/action_controller/session/cookie_store.rb +++ b/actionpack/lib/action_controller/session/cookie_store.rb @@ -89,16 +89,14 @@ module ActionController end def call(env) - session_data = AbstractStore::SessionHash.new(self, env) - original_value = session_data.dup - - env[ENV_SESSION_KEY] = session_data + env[ENV_SESSION_KEY] = AbstractStore::SessionHash.new(self, env) env[ENV_SESSION_OPTIONS_KEY] = @default_options status, headers, body = @app.call(env) - unless env[ENV_SESSION_KEY] == original_value - session_data = marshal(env[ENV_SESSION_KEY].to_hash) + session_data = env[ENV_SESSION_KEY] + if !session_data.is_a?(AbstractStore::SessionHash) || session_data.send(:loaded?) + session_data = marshal(session_data.to_hash) raise CookieOverflow if session_data.size > MAX @@ -153,7 +151,7 @@ module ActionController # Marshal a session hash into safe cookie data. Include an integrity hash. def marshal(session) - @verifier.generate( persistent_session_id!(session)) + @verifier.generate(persistent_session_id!(session)) end # Unmarshal cookie data to a hash and verify its integrity. |