Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Lib/idlelib/idle_test/test_iomenu.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"Test , coverage 17%."

from idlelib import iomenu
import os
import unittest
from unittest import mock
from test.support import requires
from tkinter import Tk
from tkinter import Tk, TclVersion
from idlelib.editor import EditorWindow
from idlelib import util
from idlelib import macosx, util
from idlelib.idle_test.mock_idle import Func

# Fail if either tokenize.open and t.detect_encoding does not exist.
Expand Down Expand Up @@ -38,6 +40,17 @@ def tearDownClass(cls):
def test_init(self):
self.assertIs(self.io.editwin, self.editwin)

def test_defaultfilename_tilde(self):
# gh-59568: escape a leading tilde for Tcl older than 9.
io = self.io
with mock.patch.object(io, 'filename', os.path.join('dir', '~file.py')):
dirname, base = io.defaultfilename()
self.assertEqual(dirname, 'dir')
if TclVersion < 9 and not macosx.isAquaTk():
self.assertEqual(base, os.path.join(os.curdir, '~file.py'))
else:
self.assertEqual(base, '~file.py')

def test_fixnewlines_end(self):
eq = self.assertEqual
io = self.io
Expand Down
9 changes: 8 additions & 1 deletion Lib/idlelib/iomenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import tempfile
import tokenize

from tkinter import TclVersion
from tkinter import filedialog
from tkinter import messagebox
from tkinter.simpledialog import askstring # loadfile encoding.

from idlelib.config import idleConf
from idlelib import macosx
from idlelib.util import py_extensions

py_extensions = ' '.join("*"+ext for ext in py_extensions)
Expand Down Expand Up @@ -405,7 +407,12 @@ def askopenfile(self):

def defaultfilename(self, mode="open"):
if self.filename:
return os.path.split(self.filename)
dirname, base = os.path.split(self.filename)
if base[:1] == '~' and TclVersion < 9 and not macosx.isAquaTk():
# Tcl before version 9 substitutes a leading tilde in
# a file name (gh-59568). The macOS dialog does not.
base = os.path.join(os.curdir, base)
return dirname, base
elif self.dirname:
return self.dirname, ""
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix "Save As" and "Open" dialogs in IDLE for a file whose name starts with
``~`` on Windows and X11 with Tcl/Tk older than 9.
Loading