diff --git a/Lib/ntpath.py b/Lib/ntpath.py index ee1a2157a14..6732aa22cb1 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -386,7 +386,7 @@ def expandvars(path): index = path.index(c) res += c + path[:index + 1] except ValueError: - res += path + res += c + path index = pathlen - 1 elif c == percent: # variable or '%' if path[index + 1:index + 2] == percent: diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index c8d84a7467c..dacddded3dd 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -237,6 +237,7 @@ def test_expandvars(self): tester('ntpath.expandvars("%?bar%")', "%?bar%") tester('ntpath.expandvars("%foo%%bar")', "bar%bar") tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar") + tester('ntpath.expandvars("bar\'%foo%")', "bar\'%foo%") @unittest.skipUnless(support.FS_NONASCII, 'need support.FS_NONASCII') def test_expandvars_nonascii(self): diff --git a/Misc/NEWS b/Misc/NEWS index 6534443f07b..822e3fdf918 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -30,6 +30,8 @@ Core and Builtins Library ------- +- Issue #23742: ntpath.expandvars() no longer loses unbalanced single quotes. + - Issue #21717: The zipfile.ZipFile.open function now supports 'x' (exclusive creation) mode.