From 535adfebba37af5da5b373b9c46b9760bde9011c Mon Sep 17 00:00:00 2001 From: saint Date: Mon, 9 Sep 2024 22:11:27 +1000 Subject: [PATCH] v0.6 Further attempt to get this reverse dobule encoding right now --- goss-correctencoding.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/goss-correctencoding.rb b/goss-correctencoding.rb index 97d8af0..479ec47 100644 --- a/goss-correctencoding.rb +++ b/goss-correctencoding.rb @@ -32,6 +32,18 @@ class GossamerForumsCorrectEncoding < ImportScripts::Base # Method to detect and fix text encoding def fix_text_encoding(content) + begin + # Treat as Windows-1252 (cp1252) and then decode into UTF-8 + corrected_content = content.encode('CP1252').force_encoding('UTF-8') + rescue Encoding::UndefinedConversionError => e + puts "Error during encoding conversion: #{e.message}" + puts e.backtrace.join("\n") # Print the full stack trace + return content # Return the original content if conversion fails + end + + corrected_content + end + # Ensure the content is treated as UTF-8 (even if incorrectly encoded) content.force_encoding('UTF-8')