This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 8b324e62 Bug - incorrectly converted
8b324e62 is described below

commit 8b324e62397cbe4f4550c571cbbc998f50e58ac4
Author: Sebb <s...@apache.org>
AuthorDate: Fri May 3 15:00:42 2024 +0100

    Bug - incorrectly converted
---
 lib/whimsy/asf/string-utils.rb | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/whimsy/asf/string-utils.rb b/lib/whimsy/asf/string-utils.rb
index b660273d..6e7a0e60 100644
--- a/lib/whimsy/asf/string-utils.rb
+++ b/lib/whimsy/asf/string-utils.rb
@@ -58,13 +58,12 @@ module ASFString
 
   # fix encoding errors
   def self.fix_encoding(text)
-    result = text
-
-    if encoding == Encoding::BINARY
-      result = encode('utf-8', invalid: :replace, undef: :replace)
+  
+    if text.encoding == Encoding::BINARY
+      return text.encode('utf-8', invalid: :replace, undef: :replace)
     end
+    return text
 
-    result
   end
 end
 
@@ -79,4 +78,7 @@ if __FILE__ == $0
   # puts txt
   puts ASFString.word_wrap(txt)
   puts ASFString.reflow(txt)
+  text="\x05\x00\x68\x65\x6c\x6c\x6f"
+  text.force_encoding(Encoding::BINARY)
+  puts ASFString.fix_encoding(text)
 end

Reply via email to