https://github.com/python/cpython/commit/217d57fc3c9a8ec45dfccd3aab9a05dbf6656da0
commit: 217d57fc3c9a8ec45dfccd3aab9a05dbf6656da0
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: ncoghlan <[email protected]>
date: 2024-05-24T14:52:20Z
summary:

[3.13] GH-119496: accept UTF-8 BOM in .pth files (GH-119508)

`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 bf5b6467f8cc06759f3396ab1a8ad64fe7d1db2e)

Co-authored-by: Alyssa Coghlan <[email protected]>
Co-authored-by: Inada Naoki <[email protected]>

files:
M Lib/site.py

diff --git a/Lib/site.py b/Lib/site.py
index f1a6d9cf66fdc3..7eace190f5ab21 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -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("utf-8-sig")
     except UnicodeDecodeError:
         # Fallback to locale encoding for backward compatibility.
         # We will deprecate this fallback in the future.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to