Skip to content

Commit bf5b646

Browse files
ncoghlanmethane
andauthored
GH-119496: accept UTF-8 BOM in .pth files (GH-119503)
`Out-File -Encoding utf8` and similar commands in Windows Powershell 5.1 emit UTF-8 with a BOM marker, which the regular `utf-8` codec decodes incorrectly. `utf-8-sig` accepts a BOM, but also works correctly without one. This change also makes .pth files match the way Python source files are handled. Co-authored-by: Inada Naoki <songofacandy@gmail.com>
1 parent 92fab33 commit bf5b646

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Lib/site.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ def addpackage(sitedir, name, known_paths):
185185
return
186186

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

0 commit comments

Comments
 (0)