From 655a2619f8c17c9f654d90015463c331967e833a Mon Sep 17 00:00:00 2001 From: saint Date: Mon, 9 Sep 2024 17:30:37 +1000 Subject: [PATCH] v0.4 - Add debugging --- goss-correctencoding.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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: '?')