]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-85320: Use UTF-8 for IDLE configuration and breakpoint files (GH-152475...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 29 Jun 2026 08:41:27 +0000 (10:41 +0200)
committerGitHub <noreply@github.com>
Mon, 29 Jun 2026 08:41:27 +0000 (11:41 +0300)
They were read and written using the locale encoding, which could corrupt
non-ASCII paths and made them non-portable.
(cherry picked from commit f6e904e1a666cb1e5664750b1c3d8f89cba3a769)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Lib/idlelib/News3.txt
Lib/idlelib/config.py
Lib/idlelib/pyshell.py
Misc/NEWS.d/next/IDLE/2026-06-28-06-46-46.gh-issue-85320.Hq2vKn.rst [new file with mode: 0644]

index 10ed90cd6b56d2c0ec5baebeba74c5ebdeae76bd..306b494e5f04515419813e2ff27b8ffcd6c4ccbe 100644 (file)
@@ -4,6 +4,11 @@ Released after 2024-10-07
 =========================
 
 
+gh-85320: IDLE now reads and writes its configuration files and the
+breakpoints file using UTF-8 instead of the locale encoding.
+Files with non-ASCII characters and non-UTF-8 encoding may need
+to be opened in an editor and resaved with UTF-8 encoding.
+
 gh-143774: Better explain the operation of Format / Format Paragraph.
 Patch by Terry J. Reedy.
 
index d10c88a43f9231d30927f1ed49512d1c401874f5..21873d252dc9babb38338e14778f1576762325c3 100644 (file)
@@ -73,8 +73,9 @@ class IdleConfParser(ConfigParser):
 
     def Load(self):
         "Load the configuration file from disk."
-        if self.file:
-            self.read(self.file)
+        if self.file and os.path.exists(self.file):
+            with open(self.file, encoding='utf-8', errors='replace') as f:
+                self.read_file(f)
 
 class IdleUserConfParser(IdleConfParser):
     """
@@ -133,10 +134,10 @@ class IdleUserConfParser(IdleConfParser):
         if fname and fname[0] != '#':
             if not self.IsEmpty():
                 try:
-                    cfgFile = open(fname, 'w')
+                    cfgFile = open(fname, 'w', encoding='utf-8')
                 except OSError:
                     os.unlink(fname)
-                    cfgFile = open(fname, 'w')
+                    cfgFile = open(fname, 'w', encoding='utf-8')
                 with cfgFile:
                     self.write(cfgFile)
             elif os.path.exists(self.file):
index f027f82d8491ae58af4ee8ea145c1f70044c1fcc..68d2002c85e17a82c86ddb15dd12faa81f0a0e05 100755 (executable)
@@ -242,12 +242,13 @@ class PyShellEditorWindow(EditorWindow):
         breaks = self.breakpoints
         filename = self.io.filename
         try:
-            with open(self.breakpointPath) as fp:
+            with open(self.breakpointPath,
+                      encoding='utf-8', errors='replace') as fp:
                 lines = fp.readlines()
         except OSError:
             lines = []
         try:
-            with open(self.breakpointPath, "w") as new_file:
+            with open(self.breakpointPath, "w", encoding='utf-8') as new_file:
                 for line in lines:
                     if not line.startswith(filename + '='):
                         new_file.write(line)
@@ -272,7 +273,8 @@ class PyShellEditorWindow(EditorWindow):
         if filename is None:
             return
         if os.path.isfile(self.breakpointPath):
-            with open(self.breakpointPath) as fp:
+            with open(self.breakpointPath,
+                      encoding='utf-8', errors='replace') as fp:
                 lines = fp.readlines()
             for line in lines:
                 if line.startswith(filename + '='):
diff --git a/Misc/NEWS.d/next/IDLE/2026-06-28-06-46-46.gh-issue-85320.Hq2vKn.rst b/Misc/NEWS.d/next/IDLE/2026-06-28-06-46-46.gh-issue-85320.Hq2vKn.rst
new file mode 100644 (file)
index 0000000..ec34bf8
--- /dev/null
@@ -0,0 +1,4 @@
+IDLE now reads and writes its configuration files and the breakpoints file
+using UTF-8 instead of the locale encoding.  This keeps non-ASCII data (such
+as non-ASCII paths) from being corrupted and makes the files portable between
+environments.