diff options
author | Francesco Rodríguez <frodsan@me.com> | 2018-10-08 10:57:18 +0200 |
---|---|---|
committer | Francesco Rodríguez <frodsan@me.com> | 2018-10-12 07:42:51 +0200 |
commit | e52b223487c4a72ccdd6d631318fc3cfcf8097ba (patch) | |
tree | b268e66d7029647f4bc8b30df216c52e158cee67 | |
parent | 8df7ed3b88fc9f19446d7207a745a331893b81cd (diff) | |
download | rails-e52b223487c4a72ccdd6d631318fc3cfcf8097ba.tar.gz rails-e52b223487c4a72ccdd6d631318fc3cfcf8097ba.tar.bz2 rails-e52b223487c4a72ccdd6d631318fc3cfcf8097ba.zip |
Deprecate Unicode#downcase/upcase/swapcase.
Use String methods directly instead.
-rw-r--r-- | activesupport/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/multibyte/chars.rb | 25 | ||||
-rw-r--r-- | activesupport/lib/active_support/multibyte/unicode.rb | 19 | ||||
-rw-r--r-- | activesupport/test/multibyte_chars_test.rb | 6 |
4 files changed, 22 insertions, 33 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index b796df26aa..4e709e0a30 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* Deprecate `ActiveSupport::Multibyte::Unicode#downcase/upcase/swapcase` in favor of + `String#downcase/upcase/swapcase`. + + *Francesco Rodríguez* + * Add `ActiveSupport::ParameterFilter`. *Yoshiyuki Kinjo* diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index 499a206f49..fec6667ce7 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -120,27 +120,6 @@ module ActiveSupport #:nodoc: slice(0...translate_offset(limit)) end - # Converts characters in the string to uppercase. - # - # 'Laurent, où sont les tests ?'.mb_chars.upcase.to_s # => "LAURENT, OÙ SONT LES TESTS ?" - def upcase - chars Unicode.upcase(@wrapped_string) - end - - # Converts characters in the string to lowercase. - # - # 'VĚDA A VÝZKUM'.mb_chars.downcase.to_s # => "věda a výzkum" - def downcase - chars Unicode.downcase(@wrapped_string) - end - - # Converts characters in the string to the opposite case. - # - # 'El Cañón'.mb_chars.swapcase.to_s # => "eL cAÑÓN" - def swapcase - chars Unicode.swapcase(@wrapped_string) - end - # Converts the first character to uppercase and the remainder to lowercase. # # 'über'.mb_chars.capitalize.to_s # => "Über" @@ -153,7 +132,7 @@ module ActiveSupport #:nodoc: # "ÉL QUE SE ENTERÓ".mb_chars.titleize.to_s # => "Él Que Se Enteró" # "日本語".mb_chars.titleize.to_s # => "日本語" def titleize - chars(downcase.to_s.gsub(/\b('?\S)/u) { Unicode.upcase($1) }) + chars(downcase.to_s.gsub(/\b('?\S)/u) { $1.upcase }) end alias_method :titlecase, :titleize @@ -205,7 +184,7 @@ module ActiveSupport #:nodoc: to_s.as_json(options) end - %w(capitalize downcase reverse tidy_bytes upcase).each do |method| + %w(capitalize reverse tidy_bytes).each do |method| define_method("#{method}!") do |*args| @wrapped_string = send(method, *args).to_s self diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index 4f0e1165ef..a3261126d6 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -115,16 +115,15 @@ module ActiveSupport end end - def downcase(string) - string.downcase - end - - def upcase(string) - string.upcase - end - - def swapcase(string) - string.swapcase + %w(downcase upcase swapcase).each do |method| + define_method(method) do |string| + ActiveSupport::Deprecation.warn(<<-MSG.squish) + ActiveSupport::Multibyte::Unicode##{method} is deprecated and + will be removed from Rails 6.1. Use String methods directly. + MSG + + string.send(method) + end end private diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index 11c4822748..af63779917 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -719,6 +719,12 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase assert_equal BYTE_STRING.dup.mb_chars.class, ActiveSupport::Multibyte::Chars end + def test_unicode_deprecations + assert_deprecated { ActiveSupport::Multibyte::Unicode.downcase("") } + assert_deprecated { ActiveSupport::Multibyte::Unicode.upcase("") } + assert_deprecated { ActiveSupport::Multibyte::Unicode.swapcase("") } + end + private def string_from_classes(classes) |