mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ActiveSupport::Base64.encode64s since Base64 is deprecated
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8817 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
fbd7ec3c9f
commit
3335bd12c8
5 changed files with 13 additions and 11 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
begin
|
||||||
|
require 'base64'
|
||||||
|
rescue LoadError
|
||||||
|
end
|
||||||
|
|
||||||
module ActiveSupport
|
module ActiveSupport
|
||||||
if defined? ::Base64
|
if defined? ::Base64
|
||||||
Base64 = ::Base64
|
Base64 = ::Base64
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
require 'base64'
|
require 'active_support/base64'
|
||||||
|
|
||||||
require 'active_support/core_ext/base64/encoding'
|
require 'active_support/core_ext/base64/encoding'
|
||||||
|
|
||||||
module Base64#:nodoc:
|
ActiveSupport::Base64.extend ActiveSupport::CoreExtensions::Base64::Encoding
|
||||||
extend ActiveSupport::CoreExtensions::Base64::Encoding
|
|
||||||
end
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ module ActiveSupport #:nodoc:
|
||||||
# Encodes the value as base64 without the newline breaks. This makes the base64 encoding readily usable as URL parameters
|
# 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.
|
# or memcache keys without further processing.
|
||||||
def encode64s(value)
|
def encode64s(value)
|
||||||
::Base64.encode64(value).gsub(/\n/, '')
|
encode64(value).gsub(/\n/, '')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,9 +77,9 @@ module ActiveSupport #:nodoc:
|
||||||
"boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) },
|
"boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) },
|
||||||
"string" => Proc.new { |string| string.to_s },
|
"string" => Proc.new { |string| string.to_s },
|
||||||
"yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
|
"yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
|
||||||
"base64Binary" => Proc.new { |bin| Base64.decode64(bin) },
|
"base64Binary" => Proc.new { |bin| ActiveSupport::Base64.decode64(bin) },
|
||||||
"file" => Proc.new do |file, entity|
|
"file" => Proc.new do |file, entity|
|
||||||
f = StringIO.new(Base64.decode64(file))
|
f = StringIO.new(ActiveSupport::Base64.decode64(file))
|
||||||
f.extend(FileLike)
|
f.extend(FileLike)
|
||||||
f.original_filename = entity['name']
|
f.original_filename = entity['name']
|
||||||
f.content_type = entity['content_type']
|
f.content_type = entity['content_type']
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'abstract_unit'
|
||||||
|
|
||||||
class Base64Test < Test::Unit::TestCase
|
class Base64Test < Test::Unit::TestCase
|
||||||
def test_no_newline_in_encoded_value
|
def test_no_newline_in_encoded_value
|
||||||
assert_match /\n/, Base64.encode64("oneverylongstringthatwouldnormallybesplitupbynewlinesbytheregularbase64")
|
assert_match(/\n/, ActiveSupport::Base64.encode64("oneverylongstringthatwouldnormallybesplitupbynewlinesbytheregularbase64"))
|
||||||
assert_no_match /\n/, Base64.encode64s("oneverylongstringthatwouldnormallybesplitupbynewlinesbytheregularbase64")
|
assert_no_match(/\n/, ActiveSupport::Base64.encode64s("oneverylongstringthatwouldnormallybesplitupbynewlinesbytheregularbase64"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue