diff options
Diffstat (limited to 'lib/gitlab/encoding_helper.rb')
-rw-r--r-- | lib/gitlab/encoding_helper.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/gitlab/encoding_helper.rb b/lib/gitlab/encoding_helper.rb index 8ee53d0de28..50e7631d983 100644 --- a/lib/gitlab/encoding_helper.rb +++ b/lib/gitlab/encoding_helper.rb @@ -64,6 +64,15 @@ module Gitlab detect && detect[:type] == :binary end + # This is like encode_utf8 except we skip autodetection of the encoding. We + # assume the data must be interpreted as UTF-8. + def encode_utf8_no_detect(message) + message = force_encode_utf8(message) + return message if message.valid_encoding? + + message.encode(Encoding::UTF_8, invalid: :replace, undef: :replace) + end + def encode_utf8(message, replace: "") message = force_encode_utf8(message) return message if message.valid_encoding? |