aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG3
-rw-r--r--activesupport/lib/active_support/core_ext/base64.rb7
-rw-r--r--activesupport/lib/active_support/core_ext/base64/encoding.rb13
-rw-r--r--activesupport/test/core_ext/base64_ext_test.rb8
4 files changed, 31 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index a8177c680a..38294ebef7 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added Base64.encode64s to encode values in base64 without the newlines. This makes the values immediately usable as URL parameters or memcache keys without further processing [DHH]
+
* Remove :nodoc: entries around the ActiveSupport test/unit assertions. #10946 [dancroak, jamesh]
* Add Time.zone_default accessor for setting the default time zone. Rails::Configuration.time_zone sets this. #10982 [Geoff Buesing]
@@ -40,6 +42,7 @@
* Introduce ActiveSupport::TimeWithZone, for wrapping Time instances with a TimeZone. Introduce instance methods to Time for creating TimeWithZone instances, and class methods for managing a global time zone. [Geoff Buesing]
+>>>>>>> .r8815
* Replace non-dst-aware TimeZone class with dst-aware class from tzinfo_timezone plugin. TimeZone#adjust and #unadjust are no longer available; tzinfo gem must now be present in order to perform time zone calculations, via #local_to_utc and #utc_to_local methods. [Geoff Buesing]
* Extract ActiveSupport::Callbacks from Active Record, test case setup and teardown, and ActionController::Dispatcher. #10727 [Josh Peek]
diff --git a/activesupport/lib/active_support/core_ext/base64.rb b/activesupport/lib/active_support/core_ext/base64.rb
new file mode 100644
index 0000000000..d8b1813851
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/base64.rb
@@ -0,0 +1,7 @@
+require 'base64'
+
+require 'active_support/core_ext/base64/encoding'
+
+module Base64#:nodoc:
+ extend ActiveSupport::CoreExtensions::Base64::Encoding
+end
diff --git a/activesupport/lib/active_support/core_ext/base64/encoding.rb b/activesupport/lib/active_support/core_ext/base64/encoding.rb
new file mode 100644
index 0000000000..19671992d2
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/base64/encoding.rb
@@ -0,0 +1,13 @@
+module ActiveSupport #:nodoc:
+ module CoreExtensions #:nodoc:
+ module Base64 #:nodoc:
+ module Encoding
+ # 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.
+ def encode64s(value)
+ ::Base64.encode64(value).gsub(/\n/, '')
+ end
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/activesupport/test/core_ext/base64_ext_test.rb b/activesupport/test/core_ext/base64_ext_test.rb
new file mode 100644
index 0000000000..aafbbd8539
--- /dev/null
+++ b/activesupport/test/core_ext/base64_ext_test.rb
@@ -0,0 +1,8 @@
+require 'abstract_unit'
+
+class Base64Test < Test::Unit::TestCase
+ def test_no_newline_in_encoded_value
+ assert_match /\n/, Base64.encode64("oneverylongstringthatwouldnormallybesplitupbynewlinesbytheregularbase64")
+ assert_no_match /\n/, Base64.encode64s("oneverylongstringthatwouldnormallybesplitupbynewlinesbytheregularbase64")
+ end
+end