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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def _getfinalpathname_nonstrict(path):

# Non-strict algorithm is to find as much of the target directory
# as we can and join the rest.
tail = ''
tail = path[:0]
while path:
try:
path = _getfinalpathname(path)
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ntpath
import os
import string
import sys
import unittest
import warnings
Expand Down Expand Up @@ -321,6 +322,16 @@ def test_realpath_basic(self):
self.assertPathEqual(ntpath.realpath(os.fsencode(ABSTFN + "1")),
os.fsencode(ABSTFN))

# gh-88013: call ntpath.realpath with binary drive name may raise a
# TypeError. The drive should not exist to reproduce the bug.
for c in string.ascii_uppercase:
d = f"{c}:\\"
if not ntpath.exists(d):
break
else:
raise OSError("No free drive letters available")
self.assertEqual(ntpath.realpath(d), d)

@os_helper.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
def test_realpath_strict(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a bug where :exc:`TypeError` was raised when calling
:func:`ntpath.realpath` with a bytes parameter in some cases.