diff options
author | Sergey Nartimov <just.lest@gmail.com> | 2012-01-01 20:57:55 +0300 |
---|---|---|
committer | Sergey Nartimov <just.lest@gmail.com> | 2012-01-02 22:48:15 +0300 |
commit | 0f2f8003d2351079ce6ec0e706e474d8024839cc (patch) | |
tree | bae06d09fd0a6904936244feae7ddf698ef97187 | |
parent | f3e079e8b54da1c4d0511495ced3f68c1b7a46f1 (diff) | |
download | rails-0f2f8003d2351079ce6ec0e706e474d8024839cc.tar.gz rails-0f2f8003d2351079ce6ec0e706e474d8024839cc.tar.bz2 rails-0f2f8003d2351079ce6ec0e706e474d8024839cc.zip |
remove ActiveSupport::Base64 in favor of ::Base64
12 files changed, 35 insertions, 63 deletions
diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 594ba7a7b8..09ff376a91 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -141,11 +141,11 @@ module ActionController end def decode_credentials(request) - ActiveSupport::Base64.decode64(request.authorization.split(' ', 2).last || '') + ::Base64.decode64(request.authorization.split(' ', 2).last || '') end def encode_credentials(user_name, password) - "Basic #{ActiveSupport::Base64.strict_encode64("#{user_name}:#{password}")}" + "Basic #{::Base64.strict_encode64("#{user_name}:#{password}")}" end def authentication_request(controller, realm) @@ -289,7 +289,7 @@ module ActionController t = time.to_i hashed = [t, secret_key] digest = ::Digest::MD5.hexdigest(hashed.join(":")) - ActiveSupport::Base64.strict_encode64("#{t}:#{digest}") + ::Base64.strict_encode64("#{t}:#{digest}") end # Might want a shorter timeout depending on whether the request @@ -298,7 +298,7 @@ module ActionController # allow a user to use new nonce without prompting user again for their # username and password. def validate_nonce(secret_key, request, value, seconds_to_timeout=5*60) - t = ActiveSupport::Base64.decode64(value).split(":").first.to_i + t = ::Base64.decode64(value).split(":").first.to_i nonce(secret_key, t) == value && (t - Time.now.to_i).abs <= seconds_to_timeout end diff --git a/actionpack/test/controller/http_basic_authentication_test.rb b/actionpack/test/controller/http_basic_authentication_test.rb index 364e96d4f6..7286b249c7 100644 --- a/actionpack/test/controller/http_basic_authentication_test.rb +++ b/actionpack/test/controller/http_basic_authentication_test.rb @@ -132,6 +132,6 @@ class HttpBasicAuthenticationTest < ActionController::TestCase private def encode_credentials(username, password) - "Basic #{ActiveSupport::Base64.encode64("#{username}:#{password}")}" + "Basic #{::Base64.encode64("#{username}:#{password}")}" end end diff --git a/actionpack/test/dispatch/request/xml_params_parsing_test.rb b/actionpack/test/dispatch/request/xml_params_parsing_test.rb index d8fa751548..0984f00066 100644 --- a/actionpack/test/dispatch/request/xml_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/xml_params_parsing_test.rb @@ -41,7 +41,7 @@ class XmlParamsParsingTest < ActionDispatch::IntegrationTest test "parses single file" do with_test_routing do - xml = "<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></person>" + xml = "<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{::Base64.encode64('ABC')}</avatar></person>" post "/parse", xml, default_headers assert_response :ok @@ -55,7 +55,7 @@ class XmlParamsParsingTest < ActionDispatch::IntegrationTest test "logs error if parsing unsuccessful" do with_test_routing do output = StringIO.new - xml = "<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></pineapple>" + xml = "<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{::Base64.encode64('ABC')}</avatar></pineapple>" post "/parse", xml, default_headers.merge('action_dispatch.show_exceptions' => true, 'action_dispatch.logger' => Logger.new(output)) assert_response :error output.rewind && err = output.read @@ -80,8 +80,8 @@ class XmlParamsParsingTest < ActionDispatch::IntegrationTest <person> <name>David</name> <avatars> - <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> + <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> </avatars> </person> end_body diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb index e3bbd06f7e..1029bed064 100644 --- a/activerecord/lib/active_record/session_store.rb +++ b/activerecord/lib/active_record/session_store.rb @@ -51,11 +51,11 @@ module ActiveRecord class SessionStore < ActionDispatch::Session::AbstractStore module ClassMethods # :nodoc: def marshal(data) - ActiveSupport::Base64.encode64(Marshal.dump(data)) if data + ::Base64.encode64(Marshal.dump(data)) if data end def unmarshal(data) - Marshal.load(ActiveSupport::Base64.decode64(data)) if data + Marshal.load(::Base64.decode64(data)) if data end def drop_table! @@ -169,11 +169,11 @@ module ActiveRecord # are implemented as class methods that you may override. By default, # marshaling data is # - # ActiveSupport::Base64.encode64(Marshal.dump(data)) + # ::Base64.encode64(Marshal.dump(data)) # # and unmarshaling data is # - # Marshal.load(ActiveSupport::Base64.decode64(data)) + # Marshal.load(::Base64.decode64(data)) # # This marshaling behavior is intended to store the widest range of # binary session data in a +text+ column. For higher performance, diff --git a/activeresource/test/cases/authorization_test.rb b/activeresource/test/cases/authorization_test.rb index 17cd9b30fc..dabc40dfe7 100644 --- a/activeresource/test/cases/authorization_test.rb +++ b/activeresource/test/cases/authorization_test.rb @@ -53,7 +53,7 @@ class AuthorizationTest < Test::Unit::TestCase authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] - assert_equal ["david", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1] + assert_equal ["david", "test123"], ::Base64.decode64(authorization[1]).split(":")[0..1] end def test_authorization_header_with_username_but_no_password @@ -62,7 +62,7 @@ class AuthorizationTest < Test::Unit::TestCase authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] - assert_equal ["david"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1] + assert_equal ["david"], ::Base64.decode64(authorization[1]).split(":")[0..1] end def test_authorization_header_with_password_but_no_username @@ -71,7 +71,7 @@ class AuthorizationTest < Test::Unit::TestCase authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] - assert_equal ["", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1] + assert_equal ["", "test123"], ::Base64.decode64(authorization[1]).split(":")[0..1] end def test_authorization_header_with_decoded_credentials_from_url @@ -80,7 +80,7 @@ class AuthorizationTest < Test::Unit::TestCase authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] - assert_equal ["my@email.com", "123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1] + assert_equal ["my@email.com", "123"], ::Base64.decode64(authorization[1]).split(":")[0..1] end def test_authorization_header_explicitly_setting_username_and_password @@ -92,7 +92,7 @@ class AuthorizationTest < Test::Unit::TestCase authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] - assert_equal ["david", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1] + assert_equal ["david", "test123"], ::Base64.decode64(authorization[1]).split(":")[0..1] end def test_authorization_header_explicitly_setting_username_but_no_password @@ -102,7 +102,7 @@ class AuthorizationTest < Test::Unit::TestCase authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] - assert_equal ["david"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1] + assert_equal ["david"], ::Base64.decode64(authorization[1]).split(":")[0..1] end def test_authorization_header_explicitly_setting_password_but_no_username @@ -112,7 +112,7 @@ class AuthorizationTest < Test::Unit::TestCase authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] - assert_equal ["", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1] + assert_equal ["", "test123"], ::Base64.decode64(authorization[1]).split(":")[0..1] end def test_authorization_header_if_credentials_supplied_and_auth_type_is_basic @@ -122,7 +122,7 @@ class AuthorizationTest < Test::Unit::TestCase authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] - assert_equal ["david", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1] + assert_equal ["david", "test123"], ::Base64.decode64(authorization[1]).split(":")[0..1] end def test_authorization_header_if_credentials_supplied_and_auth_type_is_digest diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index e8f148b972..dbf0c25c5c 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -52,7 +52,6 @@ module ActiveSupport # TODO: Narrow this list down eager_autoload do autoload :BacktraceCleaner - autoload :Base64 autoload :BasicObject autoload :Benchmarkable autoload :Cache diff --git a/activesupport/lib/active_support/base64.rb b/activesupport/lib/active_support/base64.rb deleted file mode 100644 index 41a1a3469d..0000000000 --- a/activesupport/lib/active_support/base64.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'base64' - -module ActiveSupport - Base64 = ::Base64 - - # *DEPRECATED*: Use +Base64.strict_encode64+ instead. - # - # Encodes the value as base64 without the newline breaks. This makes the base64 encoding readily usable as URL parameters - # or memcache keys without further processing. - # - # ActiveSupport::Base64.encode64s("Original unencoded string") - # # => "T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==" - def Base64.encode64s(value) - ActiveSupport::Deprecation.warn "encode64s " \ - "is deprecated. Use Base64.strict_encode64 instead", caller - strict_encode64(value) - end -end diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb index 476ba0b3d1..6ec5a04933 100644 --- a/activesupport/lib/active_support/message_encryptor.rb +++ b/activesupport/lib/active_support/message_encryptor.rb @@ -1,5 +1,5 @@ require 'openssl' -require 'active_support/base64' +require 'base64' module ActiveSupport # MessageEncryptor is a simple way to encrypt values which get stored somewhere @@ -56,12 +56,12 @@ module ActiveSupport encrypted_data = cipher.update(@serializer.dump(value)) encrypted_data << cipher.final - [encrypted_data, iv].map {|v| ActiveSupport::Base64.strict_encode64(v)}.join("--") + [encrypted_data, iv].map {|v| ::Base64.strict_encode64(v)}.join("--") end def _decrypt(encrypted_message) cipher = new_cipher - encrypted_data, iv = encrypted_message.split("--").map {|v| ActiveSupport::Base64.decode64(v)} + encrypted_data, iv = encrypted_message.split("--").map {|v| ::Base64.decode64(v)} cipher.decrypt cipher.key = @secret diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb index 7cb5b1e82d..3b27089fa0 100644 --- a/activesupport/lib/active_support/message_verifier.rb +++ b/activesupport/lib/active_support/message_verifier.rb @@ -1,4 +1,4 @@ -require 'active_support/base64' +require 'base64' require 'active_support/core_ext/object/blank' module ActiveSupport @@ -37,14 +37,14 @@ module ActiveSupport data, digest = signed_message.split("--") if data.present? && digest.present? && secure_compare(digest, generate_digest(data)) - @serializer.load(ActiveSupport::Base64.decode64(data)) + @serializer.load(::Base64.decode64(data)) else raise InvalidSignature end end def generate(value) - data = ActiveSupport::Base64.strict_encode64(@serializer.dump(value)) + data = ::Base64.strict_encode64(@serializer.dump(value)) "#{data}--#{generate_digest(data)}" end diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index 1ea9a9d7e1..677e9910bb 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -1,4 +1,5 @@ require 'time' +require 'base64' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/string/inflections' @@ -48,7 +49,7 @@ module ActiveSupport "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| ActiveSupport::Base64.encode64(binary) }, + "binary" => Proc.new { |binary| ::Base64.encode64(binary) }, "yaml" => Proc.new { |yaml| yaml.to_yaml } } unless defined?(FORMATTING) @@ -64,7 +65,7 @@ module ActiveSupport "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) }, "string" => Proc.new { |string| string.to_s }, "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml }, - "base64Binary" => Proc.new { |bin| ActiveSupport::Base64.decode64(bin) }, + "base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) }, "binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) }, "file" => Proc.new { |file, entity| _parse_file(file, entity) } } @@ -148,14 +149,14 @@ module ActiveSupport def _parse_binary(bin, entity) #:nodoc: case entity['encoding'] when 'base64' - ActiveSupport::Base64.decode64(bin) + ::Base64.decode64(bin) else bin end end def _parse_file(file, entity) - f = StringIO.new(ActiveSupport::Base64.decode64(file)) + f = StringIO.new(::Base64.decode64(file)) f.extend(FileLike) f.original_filename = entity['name'] f.content_type = entity['content_type'] diff --git a/activesupport/test/core_ext/base64_ext_test.rb b/activesupport/test/core_ext/base64_ext_test.rb deleted file mode 100644 index 544c990b3c..0000000000 --- a/activesupport/test/core_ext/base64_ext_test.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'abstract_unit' - -class Base64Test < Test::Unit::TestCase - def test_no_newline_in_encoded_value - ActiveSupport::Deprecation.silence do - assert_match(/\n/, ActiveSupport::Base64.encode64("oneverylongstringthatwouldnormallybesplitupbynewlinesbytheregularbase64")) - assert_no_match(/\n/, ActiveSupport::Base64.encode64s("oneverylongstringthatwouldnormallybesplitupbynewlinesbytheregularbase64")) - end - end -end diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb index 11142a358f..b544742300 100644 --- a/activesupport/test/message_encryptor_test.rb +++ b/activesupport/test/message_encryptor_test.rb @@ -76,10 +76,10 @@ class MessageEncryptorTest < ActiveSupport::TestCase end def munge(base64_string) - bits = ActiveSupport::Base64.decode64(base64_string) + bits = ::Base64.decode64(base64_string) bits.reverse! - ActiveSupport::Base64.strict_encode64(bits) + ::Base64.strict_encode64(bits) end end -end
\ No newline at end of file +end |