diff --git a/goss-correctencoding.rb b/goss-correctencoding.rb index db136d9..7133461 100644 --- a/goss-correctencoding.rb +++ b/goss-correctencoding.rb @@ -1,7 +1,7 @@ # Federated Computer, Inc. # David Sainty 2024 A.D. # Gossamer Threads to Discourse -- Correct Encoding -# v0.3 Debugging +# v0.4 Debugging require 'mysql2' require 'active_record' @@ -37,8 +37,11 @@ class GossamerForumsCorrectEncoding < ImportScripts::Base original_encoding = detection[:encoding] puts "Original encoding detected: #{original_encoding}" - if original_encoding == 'ISO-8859-1' - text.force_encoding('ISO-8859-1').encode('UTF-8') + # Force the encoding to the detected one, then covnert to UTF-8 + if original_encoding == 'ISO-8859-1' || original_encoding == 'windows-1252' + # For Windows-1252 or ISO-8859-1, force the encoding and convert to UTF-8 + # text.force_encoding('ISO-8859-1').encode('UTF-8') + text.force_encoding(original_encoding).encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') else # Try to convert from detected encoding to UTF-8 text.encode('UTF-8', original_encoding, invalid: :replace, undef: :replace, replace: '?')