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')