diff options
author | Cliff Pruitt <cliff.pruitt@cliffpruitt.com> | 2019-07-17 14:12:41 -0400 |
---|---|---|
committer | Cliff Pruitt <cliff.pruitt@cliffpruitt.com> | 2019-07-26 12:18:01 -0400 |
commit | 5b0a805c6a9f22818c17ddd5641b9480ea1d668d (patch) | |
tree | 7df4e584683b61246e35e93292a263f460c10e7f /activesupport/lib | |
parent | 41bc4c6207147a5eeafa323d763e66c06e61cacf (diff) | |
download | rails-5b0a805c6a9f22818c17ddd5641b9480ea1d668d.tar.gz rails-5b0a805c6a9f22818c17ddd5641b9480ea1d668d.tar.bz2 rails-5b0a805c6a9f22818c17ddd5641b9480ea1d668d.zip |
Raise errors for ASCII-8BIT encoding in ActiveSupport::Inflector::transliterate
Adds ArgumentErrors to `ActiveSupport::Inflector::transliterate` if a string is with ASCII-8BIT which will raise an error in `unicode_normalize`.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/inflector/transliterate.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index ec6e9ccb59..61651ba101 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -56,8 +56,12 @@ module ActiveSupport # # transliterate('Jürgen', locale: :de) # # => "Juergen" + # + # Transliteration of ASCII-8BIT / BINARY strings is not + # supported and 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 not transliterate strings with ASCII-8BIT encoding" if string.encoding == ::Encoding::ASCII_8BIT I18n.transliterate( ActiveSupport::Multibyte::Unicode.tidy_bytes(string).unicode_normalize(:nfc), |