From d6461bf9f5e82195d27eb198bcaef2b5a92464b8 Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Wed, 26 Oct 2005 20:15:43 +0000 Subject: Remove fingerprinting from AR session store; fix bug in store. Closes #2612 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2754 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 4 ++ .../session/active_record_store.rb | 47 +++++++++------------- 2 files changed, 22 insertions(+), 29 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 26503aef8e..b65916e85a 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,9 @@ *SVN* +* Remove ARStore session fingerprinting. + +* Fix obscure bug in ARStore. + * Added TextHelper#strip_tags for removing HTML tags from a string (using HTMLTokenizer) #2229 [marcin@junkheap.net] * Added a reader for flash.now, so it's possible to do stuff like flash.now[:alert] ||= 'New if not set' #2422 [Caio Chassot] diff --git a/actionpack/lib/action_controller/session/active_record_store.rb b/actionpack/lib/action_controller/session/active_record_store.rb index 90a84511be..c5f49fa8bc 100644 --- a/actionpack/lib/action_controller/session/active_record_store.rb +++ b/actionpack/lib/action_controller/session/active_record_store.rb @@ -50,10 +50,10 @@ class CGI class ActiveRecordStore # The default Active Record class. class Session < ActiveRecord::Base + before_update :loaded? # Don't try to save if we haven't loaded the session before_save :marshal_data! before_save :ensure_data_not_too_big - before_update :data_changed? - + class << self # Don't try to reload ARStore::Session in dev mode. @@ -73,7 +73,6 @@ class CGI def marshal(data) Base64.encode64(Marshal.dump(data)) end def unmarshal(data) Marshal.load(Base64.decode64(data)) end - def fingerprint(data) Digest::MD5.hexdigest(data) end def create_table! connection.execute <<-end_sql @@ -109,17 +108,14 @@ class CGI end end - # Lazy-unmarshal session state. Take a fingerprint so we can detect - # whether to save changes later. + # Lazy-unmarshal session state. def data unless @data - case @data = read_attribute('data') + case data = read_attribute('data') when String - @fingerprint = self.class.fingerprint(@data) - @data = self.class.unmarshal(@data) - when nil - @data = {} - @fingerprint = nil + @data = self.class.unmarshal(data) + else + @data = data || {} end end @data @@ -127,12 +123,12 @@ class CGI private def marshal_data! - write_attribute('data', self.class.marshal(@data || {})) + write_attribute('data', self.class.marshal(self.data)) end - - def data_changed? - old_fingerprint, @fingerprint = @fingerprint, self.class.fingerprint(read_attribute('data')) - old_fingerprint != @fingerprint + + # Has the session been loaded yet? + def loaded? + !! @data end # Ensures that the data about to be stored in the database is not @@ -188,7 +184,6 @@ class CGI def marshal(data) Base64.encode64(Marshal.dump(data)) end def unmarshal(data) Marshal.load(Base64.decode64(data)) end - def fingerprint(data) Digest::MD5.hexdigest(data) end def create_table! @@connection.execute <<-end_sql @@ -220,16 +215,13 @@ class CGI @new_record end - # Lazy-unmarshal session state. Take a fingerprint so we can detect - # whether to save changes later. + # Lazy-unmarshal session state. def data 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 @@ -249,14 +241,11 @@ class CGI #{@@connection.quote(marshaled_data)} ) end_sql else - old_fingerprint, @fingerprint = @fingerprint, self.class.fingerprint(marshaled_data) - if old_fingerprint != @fingerprint - @@connection.update <<-end_sql, 'Update session' - UPDATE #{@@table_name} - SET #{@@connection.quote_column_name(@@data_column)}=#{@@connection.quote(marshaled_data)} - WHERE #{@@connection.quote_column_name(@@session_id_column)}=#{@@connection.quote(session_id)} - end_sql - end + @@connection.update <<-end_sql, 'Update session' + UPDATE #{@@table_name} + SET #{@@connection.quote_column_name(@@data_column)}=#{@@connection.quote(marshaled_data)} + WHERE #{@@connection.quote_column_name(@@session_id_column)}=#{@@connection.quote(session_id)} + end_sql end end -- cgit v1.2.3