diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-18 21:14:07 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-18 21:14:07 +0000 |
commit | f91acf0258b3d40cbb31663e965669b7199be051 (patch) | |
tree | a5a1caabd8c681b459360d92b7b62bf665c9a1eb | |
parent | 2bdac92dcf8caf9e2b45796f8af56da6a293d722 (diff) | |
download | rails-f91acf0258b3d40cbb31663e965669b7199be051.tar.gz rails-f91acf0258b3d40cbb31663e965669b7199be051.tar.bz2 rails-f91acf0258b3d40cbb31663e965669b7199be051.zip |
Ruby 1.9 compat: move from the deprecated Base64 module to ActiveSupport::Base64. Closes #10554.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8433 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionpack/lib/action_controller/http_authentication.rb | 6 | ||||
-rw-r--r-- | actionpack/lib/action_controller/session/active_record_store.rb | 15 | ||||
-rw-r--r-- | actionpack/lib/action_controller/session/cookie_store.rb | 5 | ||||
-rw-r--r-- | actionpack/test/activerecord/active_record_store_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/request_test.rb | 6 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 1 | ||||
-rw-r--r-- | activeresource/test/authorization_test.rb | 7 | ||||
-rw-r--r-- | activeresource/test/connection_test.rb | 1 | ||||
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/conversions.rb | 3 |
11 files changed, 22 insertions, 28 deletions
diff --git a/actionpack/lib/action_controller/http_authentication.rb b/actionpack/lib/action_controller/http_authentication.rb index 18a503c3ad..cd81c24e8b 100644 --- a/actionpack/lib/action_controller/http_authentication.rb +++ b/actionpack/lib/action_controller/http_authentication.rb @@ -1,5 +1,3 @@ -require 'base64' - module ActionController module HttpAuthentication # Makes it dead easy to do HTTP Basic authentication. @@ -110,11 +108,11 @@ module ActionController end def decode_credentials(request) - Base64.decode64(authorization(request).split.last || '') + ActiveSupport::Base64.decode64(authorization(request).split.last || '') end def encode_credentials(user_name, password) - "Basic #{Base64.encode64("#{user_name}:#{password}")}" + "Basic #{ActiveSupport::Base64.encode64("#{user_name}:#{password}")}" end def authentication_request(controller, realm) diff --git a/actionpack/lib/action_controller/session/active_record_store.rb b/actionpack/lib/action_controller/session/active_record_store.rb index 14747c5052..379fcd62b6 100644 --- a/actionpack/lib/action_controller/session/active_record_store.rb +++ b/actionpack/lib/action_controller/session/active_record_store.rb @@ -1,7 +1,6 @@ require 'cgi' require 'cgi/session' require 'digest/md5' -require 'base64' class CGI class Session @@ -80,8 +79,8 @@ class CGI find_by_session_id(session_id) end - def marshal(data) Base64.encode64(Marshal.dump(data)) if data end - def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end + def marshal(data) ActiveSupport::Base64.encode64(Marshal.dump(data)) if data end + def unmarshal(data) Marshal.load(ActiveSupport::Base64.decode64(data)) if data end def create_table! connection.execute <<-end_sql @@ -155,8 +154,8 @@ class CGI # The database connection, table name, and session id and data columns # are configurable class attributes. Marshaling and unmarshaling # are implemented as class methods that you may override. By default, - # marshaling data is +Base64.encode64(Marshal.dump(data))+ and - # unmarshaling data is +Marshal.load(Base64.decode64(data))+. + # marshaling data is +ActiveSupport::Base64.encode64(Marshal.dump(data))+ and + # unmarshaling data is +Marshal.load(ActiveSupport::Base64.decode64(data))+. # # This marshaling behavior is intended to store the widest range of # binary session data in a +text+ column. For higher performance, @@ -190,8 +189,8 @@ class CGI end end - def marshal(data) Base64.encode64(Marshal.dump(data)) if data end - def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end + def marshal(data) ActiveSupport::Base64.encode64(Marshal.dump(data)) if data end + def unmarshal(data) Marshal.load(ActiveSupport::Base64.decode64(data)) if data end def create_table! @@connection.execute <<-end_sql @@ -333,4 +332,4 @@ class CGI end end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_controller/session/cookie_store.rb b/actionpack/lib/action_controller/session/cookie_store.rb index 086f5a87a2..0a2a91f01e 100644 --- a/actionpack/lib/action_controller/session/cookie_store.rb +++ b/actionpack/lib/action_controller/session/cookie_store.rb @@ -1,6 +1,5 @@ require 'cgi' require 'cgi/session' -require 'base64' # to convert Marshal.dump to ASCII require 'openssl' # to generate the HMAC message digest # This cookie-based session store is the Rails default. Sessions typically @@ -130,7 +129,7 @@ class CGI::Session::CookieStore private # Marshal a session hash into safe cookie data. Include an integrity hash. def marshal(session) - data = Base64.encode64(Marshal.dump(session)).chop + data = ActiveSupport::Base64.encode64(Marshal.dump(session)).chop CGI.escape "#{data}--#{generate_digest(data)}" end @@ -142,7 +141,7 @@ class CGI::Session::CookieStore delete raise TamperedWithCookie end - Marshal.load(Base64.decode64(data)) + Marshal.load(ActiveSupport::Base64.decode64(data)) end end diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb index 707a0a75cc..61900ac252 100644 --- a/actionpack/test/activerecord/active_record_store_test.rb +++ b/actionpack/test/activerecord/active_record_store_test.rb @@ -66,7 +66,7 @@ class ActiveRecordStoreTest < ActiveRecordTestCase def test_save_unloaded_session c = session_class.connection - bogus_class = c.quote(Base64.encode64("\004\010o:\vBlammo\000")) + bogus_class = c.quote(ActiveSupport::Base64.encode64("\004\010o:\vBlammo\000")) c.insert("INSERT INTO #{session_class.table_name} ('#{session_id_column}', 'data') VALUES ('abcdefghijklmnop', #{bogus_class})") sess = session_class.find_by_session_id('abcdefghijklmnop') diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 698d3cbd2a..a81fa4d866 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -789,7 +789,7 @@ end class XmlParamsParsingTest < Test::Unit::TestCase def test_single_file - person = parse_body("<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{Base64.encode64('ABC')}</avatar></person>") + person = parse_body("<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></person>") assert_equal "image/jpg", person['person']['avatar'].content_type assert_equal "me.jpg", person['person']['avatar'].original_filename @@ -801,8 +801,8 @@ class XmlParamsParsingTest < Test::Unit::TestCase <person> <name>David</name> <avatars> - <avatar type='file' name='me.jpg' content_type='image/jpg'>#{Base64.encode64('ABC')}</avatar> - <avatar type='file' name='you.gif' content_type='image/gif'>#{Base64.encode64('DEF')}</avatar> + <avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar> + <avatar type='file' name='you.gif' content_type='image/gif'>#{ActiveSupport::Base64.encode64('DEF')}</avatar> </avatars> </person> end_body diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 9941697f3a..2a3fe1bde4 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1,4 +1,3 @@ -require 'base64' require 'yaml' require 'set' diff --git a/activeresource/test/authorization_test.rb b/activeresource/test/authorization_test.rb index 58bd36cb77..aed2e0e64b 100644 --- a/activeresource/test/authorization_test.rb +++ b/activeresource/test/authorization_test.rb @@ -1,5 +1,4 @@ require "#{File.dirname(__FILE__)}/abstract_unit" -require 'base64' class AuthorizationTest < Test::Unit::TestCase Response = Struct.new(:code) @@ -25,7 +24,7 @@ class AuthorizationTest < Test::Unit::TestCase authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] - assert_equal ["david", "test123"], Base64.decode64(authorization[1]).split(":")[0..1] + assert_equal ["david", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1] end def test_authorization_header_with_username_but_no_password @@ -34,7 +33,7 @@ class AuthorizationTest < Test::Unit::TestCase authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] - assert_equal ["david"], Base64.decode64(authorization[1]).split(":")[0..1] + assert_equal ["david"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1] end def test_authorization_header_with_password_but_no_username @@ -43,7 +42,7 @@ class AuthorizationTest < Test::Unit::TestCase authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] - assert_equal ["", "test123"], Base64.decode64(authorization[1]).split(":")[0..1] + assert_equal ["", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1] end def test_get diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb index ffad974401..307d3a94d5 100644 --- a/activeresource/test/connection_test.rb +++ b/activeresource/test/connection_test.rb @@ -1,5 +1,4 @@ require "#{File.dirname(__FILE__)}/abstract_unit" -require 'base64' class ConnectionTest < Test::Unit::TestCase ResponseCodeStub = Struct.new(:code) diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 79869c6f93..878f44bbd7 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,6 +1,6 @@ *SVN* -* Ruby 1.9 compatibility. #1689, #10466, #10468 [Cheah Chu Yeow, Pratik Naik, Jeremy Kemper] +* Ruby 1.9 compatibility. #1689, #10466, #10468, #10554 [Cheah Chu Yeow, Pratik Naik, Jeremy Kemper, Dirkjan Bussink] * TimeZone#to_s uses UTC rather than GMT. #1689 [Cheah Chu Yeow] diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index 0b3816ec01..33e6fe97bf 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -45,5 +45,7 @@ require 'active_support/json' require 'active_support/multibyte' +require 'active_support/base64' + require 'active_support/testing' diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 8021dfa87a..a758c3454b 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -1,6 +1,5 @@ require 'date' require 'cgi' -require 'base64' require 'builder' require 'xmlsimple' @@ -46,7 +45,7 @@ module ActiveSupport #:nodoc: "symbol" => Proc.new { |symbol| symbol.to_s }, "date" => Proc.new { |date| date.to_s(:db) }, "datetime" => Proc.new { |time| time.xmlschema }, - "binary" => Proc.new { |binary| Base64.encode64(binary) }, + "binary" => Proc.new { |binary| ActiveSupport::Base64.encode64(binary) }, "yaml" => Proc.new { |yaml| yaml.to_yaml } } unless defined?(XML_FORMATTING) |