summaryrefslogtreecommitdiff
path: root/test/base64
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-13 12:31:30 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-13 12:31:30 +0000
commit6b6680945ed3274cddbc34fdfd410d74081a3e94 (patch)
treea6fbc45f4dc61849dd61e5c62d3c358bd7ad85ab /test/base64
parentb4974e71dcb32d430d7d686c5de247218991ec6c (diff)
downloadruby-6b6680945ed3274cddbc34fdfd410d74081a3e94.tar.gz
* lib/base64.rb: make urlsafe mode user-friendly.
* lib/base64.rb (Base64.urlsafe_encode64): a new option "padding" to suppress the padding character ("="). * lib/base64.rb (Base64.urlsafe_decode64): now it accepts not only correctly-padded input but also unpadded input. [Feature #10740][ruby-core:67570] * test/base64/test_base64.rb: Test for above git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/base64')
-rw-r--r--test/base64/test_base64.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/base64/test_base64.rb b/test/base64/test_base64.rb
index c5e61b31ac..c2cd60adcd 100644
--- a/test/base64/test_base64.rb
+++ b/test/base64/test_base64.rb
@@ -87,6 +87,13 @@ class TestBase64 < Test::Unit::TestCase
assert_equal("_-8=", Base64.urlsafe_encode64("\xff\xef"))
end
+ def test_urlsafe_encode64_unpadded
+ assert_equal("", Base64.urlsafe_encode64("", padding: false))
+ assert_equal("AA", Base64.urlsafe_encode64("\0", padding: false))
+ assert_equal("AAA", Base64.urlsafe_encode64("\0\0", padding: false))
+ assert_equal("AAAA", Base64.urlsafe_encode64("\0\0\0", padding: false))
+ end
+
def test_urlsafe_decode64
assert_equal("", Base64.urlsafe_decode64(""))
assert_equal("\0", Base64.urlsafe_decode64("AA=="))
@@ -97,4 +104,11 @@ class TestBase64 < Test::Unit::TestCase
assert_equal("\377\377\377", Base64.urlsafe_decode64("____"))
assert_equal("\xff\xef", Base64.urlsafe_decode64("_+8="))
end
+
+ def test_urlsafe_decode64_unpadded
+ assert_equal("\0", Base64.urlsafe_decode64("AA"))
+ assert_equal("\0\0", Base64.urlsafe_decode64("AAA"))
+ assert_equal("\0\0\0", Base64.urlsafe_decode64("AAAA"))
+ assert_raise(ArgumentError) { Base64.urlsafe_decode64("AA=") }
+ end
end