Skip to content

Commit 4c0bc69

Browse files
miss-islingtonncoghlanmethane
authored
[3.12] GH-119496: accept UTF-8 BOM in .pth files (GH-119509)
`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. (cherry picked from commit bf5b646) Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com> Co-authored-by: Inada Naoki <songofacandy@gmail.com>
1 parent 078da88 commit 4c0bc69

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Lib/site.py

Lines changed: 3 additions & 1 deletion
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)