Permalink
Browse files

Ruby 1.9 compat: move from the deprecated Base64 module to ActiveSupp…

…ort::Base64. Closes #10554.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8433 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2bdac92 commit f91acf0258b3d40cbb31663e965669b7199be051 @jeremy jeremy committed Dec 18, 2007
View
6 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 @@ def authorization(request)
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)
View
15 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 @@ def find_by_session_id(session_id)
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 @@ def raise_on_session_data_overflow!
# 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 @@ def find_by_session_id(session_id)
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 @@ def logger
end
end
end
-end
+end
View
5 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 @@ def generate_digest(data)
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 @@ def unmarshal(cookie)
delete
raise TamperedWithCookie
end
- Marshal.load(Base64.decode64(data))
+ Marshal.load(ActiveSupport::Base64.decode64(data))
end
end
View
2 actionpack/test/activerecord/active_record_store_test.rb
@@ -66,7 +66,7 @@ def test_model_attribute
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')
View
6 actionpack/test/controller/request_test.rb
@@ -789,7 +789,7 @@ def process(name)
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 @@ def test_multiple_files
<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
View
1 activerecord/lib/active_record/base.rb
@@ -1,4 +1,3 @@
-require 'base64'
require 'yaml'
require 'set'
View
7 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 @@ def test_authorization_header
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 @@ def test_authorization_header_with_username_but_no_password
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 @@ def test_authorization_header_with_password_but_no_username
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
View
1 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)
View
2 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]
View
2 activesupport/lib/active_support.rb
@@ -45,5 +45,7 @@
require 'active_support/multibyte'
+require 'active_support/base64'
+
require 'active_support/testing'
View
3 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 Conversions
"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)

0 comments on commit f91acf0

Please sign in to comment.