Skip to content

Commit

Permalink
Ruby 1.9 compat: move from the deprecated Base64 module to ActiveSupp…
Browse files Browse the repository at this point in the history
…ort::Base64. Closes #10554.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8433 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Dec 18, 2007
1 parent 2bdac92 commit f91acf0
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 28 deletions.
6 changes: 2 additions & 4 deletions actionpack/lib/action_controller/http_authentication.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'base64'

module ActionController
module HttpAuthentication
# Makes it dead easy to do HTTP Basic authentication.
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions actionpack/lib/action_controller/session/active_record_store.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'cgi'
require 'cgi/session'
require 'digest/md5'
require 'base64'

class CGI
class Session
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -333,4 +332,4 @@ def logger
end
end
end
end
end
5 changes: 2 additions & 3 deletions actionpack/lib/action_controller/session/cookie_store.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand All @@ -142,7 +141,7 @@ def unmarshal(cookie)
delete
raise TamperedWithCookie
end
Marshal.load(Base64.decode64(data))
Marshal.load(ActiveSupport::Base64.decode64(data))
end
end

Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/activerecord/active_record_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions actionpack/test/controller/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion activerecord/lib/active_record/base.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'base64'
require 'yaml'
require 'set'

Expand Down
7 changes: 3 additions & 4 deletions activeresource/test/authorization_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "#{File.dirname(__FILE__)}/abstract_unit"
require 'base64'

class AuthorizationTest < Test::Unit::TestCase
Response = Struct.new(:code)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion activeresource/test/connection_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "#{File.dirname(__FILE__)}/abstract_unit"
require 'base64'

class ConnectionTest < Test::Unit::TestCase
ResponseCodeStub = Struct.new(:code)
Expand Down
2 changes: 1 addition & 1 deletion activesupport/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
2 changes: 2 additions & 0 deletions activesupport/lib/active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@

require 'active_support/multibyte'

require 'active_support/base64'

require 'active_support/testing'

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'date'
require 'cgi'
require 'base64'
require 'builder'
require 'xmlsimple'

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit f91acf0

Please sign in to comment.