From a84c027d7fb726e06f6b59458fc5d64787fe2d98 Mon Sep 17 00:00:00 2001 From: Nigel Date: Tue, 17 Oct 2023 20:32:41 +0100 Subject: [PATCH] Don't assume good/badwords files are utf8-encoded Apparently, they can be "Latin-1" - previous work assumed utf8. --- src/lib/Guiguts/SpellCheck.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/Guiguts/SpellCheck.pm b/src/lib/Guiguts/SpellCheck.pm index bdda070b..30059df8 100644 --- a/src/lib/Guiguts/SpellCheck.pm +++ b/src/lib/Guiguts/SpellCheck.pm @@ -494,10 +494,11 @@ sub spelladdgoodwords { my $fh; - # Load good words first - if ( open( $fh, "<:encoding(utf8)", "good_words.txt" ) ) { + # Load good words first - these files may not be utf8-encoded, so don't assume they are + if ( open( $fh, "<", "good_words.txt" ) ) { ::busy(); while ( my $line = <$fh> ) { + utf8::decode($line); $line =~ s/\s+$//; next if $line eq ''; $::projectdict{$line} = ''; @@ -505,8 +506,9 @@ sub spelladdgoodwords { close($fh); # The bad_words.txt file often doesn't exist, so don't error if that's the case - if ( open( $fh, "<:encoding(utf8)", "bad_words.txt" ) ) { + if ( open( $fh, "<", "bad_words.txt" ) ) { while ( my $line = <$fh> ) { + utf8::decode($line); $line =~ s/\s+$//; next if $line eq ''; $::projectbadwords{$line} = '';