From 05f9e3ef92114c2df978009073d0b47fe1323eb7 Mon Sep 17 00:00:00 2001 From: Cliff Pruitt Date: Tue, 16 Jul 2019 14:41:51 -0400 Subject: Make UTF-8 string requirement explicit for `transliterate` It's noted in #34062 that String#parameterize will raise an `Encoding::CompatibilityError` if the string is not UTF-8 encoded. The error is raised as a result of passing the string to `.unicode_normalize`. This PR raises a higher level `ArgumentError` if the provided string is not UTF-8 and updates documentation to note the encoding requirement. --- activesupport/test/transliterate_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/transliterate_test.rb b/activesupport/test/transliterate_test.rb index 9e29a93ea0..525b4a8559 100644 --- a/activesupport/test/transliterate_test.rb +++ b/activesupport/test/transliterate_test.rb @@ -57,4 +57,12 @@ 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 -- cgit v1.2.3