Skip to content

Commit

Permalink
Don't assume good/badwords files are utf8-encoded
Browse files Browse the repository at this point in the history
Apparently, they can be "Latin-1" - previous work assumed utf8.
  • Loading branch information
windymilla committed Oct 17, 2023
1 parent 9239d91 commit a84c027
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib/Guiguts/SpellCheck.pm
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +494,21 @@ 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} = '';
}
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} = '';
Expand Down

0 comments on commit a84c027

Please sign in to comment.