From 9ad1f4998546384254aadd19bfa08024c77539b9 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 4 Jul 2005 21:26:54 +0000 Subject: r2810@asus: jeremy | 2005-07-04 19:29:54 -0700 correct marshaling and fingerprinting logic git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1682 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../session/active_record_store.rb | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/actionpack/lib/action_controller/session/active_record_store.rb b/actionpack/lib/action_controller/session/active_record_store.rb index 7d9bcabc8c..d539fd2a95 100644 --- a/actionpack/lib/action_controller/session/active_record_store.rb +++ b/actionpack/lib/action_controller/session/active_record_store.rb @@ -85,12 +85,18 @@ class CGI end end - # Lazy-unmarshal session state. + # Lazy-unmarshal session state. Take a fingerprint so we can detect + # whether to save changes later. def data unless @data - marshaled_data = read_attribute('data') - @fingerprint = self.class.fingerprint(marshaled_data) - @data = self.class.unmarshal(marshaled_data) + case @data = read_attribute('data') + when String + @fingerprint = self.class.fingerprint(@data) + @data = self.class.unmarshal(@data) + when nil + @data = {} + @fingerprint = nil + end end @data end @@ -172,15 +178,24 @@ class CGI # We need to handle a normal data attribute in case of a new record. def initialize(attributes) @session_id, @data, @marshaled_data = attributes[:session_id], attributes[:data], attributes[:marshaled_data] - @new_record = !@marshaled_data.nil? + @new_record = @marshaled_data.nil? + end + + def new_record? + @new_record end # Lazy-unmarshal session state. Take a fingerprint so we can detect # whether to save changes later. def data - if @marshaled_data - @fingerprint = self.class.fingerprint(@marshaled_data) - @data, @marshaled_data = self.class.unmarshal(@marshaled_data), nil + unless @data + if @marshaled_data + @fingerprint = self.class.fingerprint(@marshaled_data) + @data, @marshaled_data = self.class.unmarshal(@marshaled_data), nil + else + @data = {} + @fingerprint = nil + end end @data end -- cgit v1.2.3