]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] 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:44:24 +0000 (10:44 +0200)
committerGitHub <noreply@github.com>
Mon, 29 Jun 2026 08:44:24 +0000 (08:44 +0000)
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 0f61da8368f211264cc74fae4773f9c2dee435d7..97becb858fea333508ea2cc943508d0e4b607ea9 100644 (file)
@@ -4,6 +4,11 @@ Released on 2026-10-01
 =========================
 
 
+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 1cabe4794500151ae381f8d41691cddac7d461a0..82afd6c49269d2dd34b80c42d6fffdad36960d73 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 b80c8e56c9281058496d673a96cd7cd6ab0a8f31..b1662491935e4a0f5b0edae9eeda7282b7a6d0fa 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.