Skip to content

Commit 85fb0be

Browse files
Fix UTF-8 encoding issue in check-shellscript-set-options (#138)
The check-shellscript-set-options hook fails on Windows when processing shell scripts containing UTF-8 characters (e.g., emojis) because it opens files without specifying an encoding, defaulting to cp1252 on Windows. This commit adds explicit UTF-8 encoding when reading files to ensure cross-platform compatibility. Fixes the error: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 3176: character maps to <undefined> Changes: - filename.read_text() -> filename.read_text(encoding='utf-8') - filename.open().readline() -> filename.open(encoding='utf-8').readline() --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 0ca8444 commit 85fb0be

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

dev_tools/check_shellscript_set_options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _sets_options_or_is_nolint(line: str, expected_options: str) -> bool:
2424

2525

2626
def _is_valid_shell_file(filename: Path, expected_options: str) -> bool:
27-
lines = filename.read_text().splitlines()
27+
lines = filename.read_text(encoding="utf-8").splitlines()
2828
return any(_sets_options_or_is_nolint(line, expected_options) for line in lines)
2929

3030

@@ -39,7 +39,7 @@ def _separate_bash_from_sh_files(filenames: Sequence[Path]) -> tuple[bool, list[
3939
sh_files = []
4040
all_valid = True
4141
for filename in filenames:
42-
first_line = filename.open().readline()
42+
first_line = filename.open(encoding="utf-8").readline()
4343
if _does_shebang_match("bash", first_line) or filename.suffix == ".bash":
4444
bash_files.append(filename)
4545
elif _does_shebang_match("sh", first_line):

0 commit comments

Comments
 (0)