v0.6 Further attempt to get this reverse dobule encoding right now
This commit is contained in:
parent
ad518a1512
commit
535adfebba
@ -32,6 +32,18 @@ class GossamerForumsCorrectEncoding < ImportScripts::Base
|
|||||||
|
|
||||||
# Method to detect and fix text encoding
|
# Method to detect and fix text encoding
|
||||||
def fix_text_encoding(content)
|
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)
|
# Ensure the content is treated as UTF-8 (even if incorrectly encoded)
|
||||||
content.force_encoding('UTF-8')
|
content.force_encoding('UTF-8')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user