From 24f669c74f5fb81f480e12a148c25a066e8c598a Mon Sep 17 00:00:00 2001 From: b0e Date: Mon, 9 Nov 2020 14:15:32 +0100 Subject: [PATCH] Fix UTF-8 encoding problem Don't convert any unknown encoding from binary to UTF-8. This breaks some chars if the str is already UTF-8. --- rt_client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rt_client.rb b/rt_client.rb index 815042c..d5d4b11 100755 --- a/rt_client.rb +++ b/rt_client.rb @@ -879,7 +879,7 @@ def compose(fields) # :nodoc: # Helper to replace control characters with string representations # When some XML libraries hit these in an XML response, bad things happen. def sterilize(str) - str.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') + str.encode!('UTF-8', str.encoding.to_s, invalid: :replace, undef: :replace, replace: '') str.gsub!(0x00.chr,'[NUL]') str.gsub!(0x01.chr,'[SOH]') str.gsub!(0x02.chr,'[STX]')