[ruby/base64] Simplify

Thanks @nobu!

https://github.com/ruby/base64/commit/39e22efa2b
This commit is contained in:
Joao Fernandes 2021-09-02 16:57:26 +01:00 committed by Hiroshi SHIBATA
parent 05a28ce5b1
commit 1b004ba0db

View File

@ -82,13 +82,7 @@ module Base64
# You can remove the padding by setting +padding+ as false.
def urlsafe_encode64(bin, padding: true)
str = strict_encode64(bin)
unless padding
if str.end_with?("==")
str.delete_suffix!("==")
elsif str.end_with?("=")
str.chop!
end
end
str.chomp!("==") or str.chomp!("=") unless padding
str.tr!("+/", "-_")
str
end