aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorCliff Pruitt <cliff.pruitt@cliffpruitt.com>2019-07-17 12:13:09 -0400
committerGitHub <noreply@github.com>2019-07-17 12:13:09 -0400
commit0deecc781a53f7125abecb4b1d301fb76b6a2bb5 (patch)
tree19eac18ee91b8ac284163b79df74af5d25c7d22b /activesupport
parente4747a4965ad7f081f6c66cadcadffe0545e4025 (diff)
downloadrails-0deecc781a53f7125abecb4b1d301fb76b6a2bb5.tar.gz
rails-0deecc781a53f7125abecb4b1d301fb76b6a2bb5.tar.bz2
rails-0deecc781a53f7125abecb4b1d301fb76b6a2bb5.zip
Revert "Make UTF-8 string requirement explicit for `ActiveSupport::Inflector.transliterate`"
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/inflector/transliterate.rb9
-rw-r--r--activesupport/test/transliterate_test.rb8
2 files changed, 2 insertions, 15 deletions
diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb
index ea7161a6ba..ec6e9ccb59 100644
--- a/activesupport/lib/active_support/inflector/transliterate.rb
+++ b/activesupport/lib/active_support/inflector/transliterate.rb
@@ -5,9 +5,8 @@ require "active_support/i18n"
module ActiveSupport
module Inflector
- # Replaces non-ASCII characters in a UTF-8 encoded string with an ASCII
- # approximation, or if none exists, a replacement character which
- # defaults to "?".
+ # Replaces non-ASCII characters with an ASCII approximation, or if none
+ # exists, a replacement character which defaults to "?".
#
# transliterate('Ærøskøbing')
# # => "AEroskobing"
@@ -57,12 +56,8 @@ module ActiveSupport
#
# transliterate('Jürgen', locale: :de)
# # => "Juergen"
- #
- # This method requires that `string` be UTF-8 encoded. Passing an argument
- # with a different string encoding will raise an ArgumentError.
def transliterate(string, replacement = "?", locale: nil)
raise ArgumentError, "Can only transliterate strings. Received #{string.class.name}" unless string.is_a?(String)
- raise ArgumentError, "Can only transliterate UTF-8 strings. Received string with encoding #{string.encoding}" unless string.encoding == ::Encoding::UTF_8
I18n.transliterate(
ActiveSupport::Multibyte::Unicode.tidy_bytes(string).unicode_normalize(:nfc),
diff --git a/activesupport/test/transliterate_test.rb b/activesupport/test/transliterate_test.rb
index 525b4a8559..9e29a93ea0 100644
--- a/activesupport/test/transliterate_test.rb
+++ b/activesupport/test/transliterate_test.rb
@@ -57,12 +57,4 @@ class TransliterateTest < ActiveSupport::TestCase
end
assert_equal "Can only transliterate strings. Received Object", exception.message
end
-
- def test_transliterate_handles_non_unicode_strings
- ascii_8bit_string = "A".b
- exception = assert_raises ArgumentError do
- assert_equal "A", ActiveSupport::Inflector.transliterate(ascii_8bit_string)
- end
- assert_equal "Can only transliterate UTF-8 strings. Received string with encoding ASCII-8BIT", exception.message
- end
end