Skip to content

Commit 873538c

Browse files
committed
fix: Enforce the UTF-8 character encoding in a read_text call in gator/entities.py.
1 parent f6fcb61 commit 873538c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

gator/entities.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ def count_entities(given_file, containing_directory, checking_function):
5151
file_contents_count = 0
5252
# create an empty dictionary of the counts
5353
file_contents_count_dictionary = {}
54-
# a valid file exists and thus it is acceptable to perform the checking
55-
# extract the text from the file_for_checking
56-
file_contents = file_for_checking.read_text()
54+
# a valid file exists and thus it is acceptable to perform the checking;
55+
# first extract the text from the file_for_checking; note that this
56+
# explicitly sets the encoding to be UTF-8 to ensure that the input of
57+
# the file will work on operating systems where the default character
58+
# encoding is not UTF-8; this commonly happens on Windows systems where
59+
# the default encoding is usually CP-1252
60+
file_contents = file_for_checking.read_text(encoding='utf-8')
5761
# use the provided checking_function to check the contents of the file
5862
# note this works since Python supports passing a function to a function
5963
file_contents_count, file_contents_count_dictionary = checking_function(

0 commit comments

Comments
 (0)