Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Accept UTF-8 BOM in .pth files
`Out-File -Encoding utf8` in Windows Powershell 5.1 emits
UTF-8 with a BOM maker, which the regular `utf-8` codec
decodes incorrectly. `utf-8-sig` accepts a BOM, but also
works correctly without one.
  • Loading branch information
ncoghlan authored May 24, 2024
commit 77a45b0e3a7ddabbf3500d7f22a13bfb157b291e
4 changes: 3 additions & 1 deletion Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def addpackage(sitedir, name, known_paths):
return

try:
pth_content = pth_content.decode()
# Accept BOM markers in .pth files as we do in source files
# (Windows PowerShell 5.1 makes it hard to emit UTF-8 files without a BOM)
pth_content = pth_content.decode(encoding="utf8-sig")
except UnicodeDecodeError:
# Fallback to locale encoding for backward compatibility.
# We will deprecate this fallback in the future.
Expand Down