File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -644,7 +644,7 @@ def _getfinalpathname_nonstrict(path):
644
644
645
645
# Non-strict algorithm is to find as much of the target directory
646
646
# as we can and join the rest.
647
- tail = ''
647
+ tail = path [: 0 ]
648
648
while path :
649
649
try :
650
650
path = _getfinalpathname (path )
Original file line number Diff line number Diff line change 1
1
import ntpath
2
2
import os
3
+ import string
3
4
import sys
4
5
import unittest
5
6
import warnings
@@ -321,6 +322,16 @@ def test_realpath_basic(self):
321
322
self .assertPathEqual (ntpath .realpath (os .fsencode (ABSTFN + "1" )),
322
323
os .fsencode (ABSTFN ))
323
324
325
+ # gh-88013: call ntpath.realpath with binary drive name may raise a
326
+ # TypeError. The drive should not exist to reproduce the bug.
327
+ for c in string .ascii_uppercase :
328
+ d = f"{ c } :\\ "
329
+ if not ntpath .exists (d ):
330
+ break
331
+ else :
332
+ raise OSError ("No free drive letters available" )
333
+ self .assertEqual (ntpath .realpath (d ), d )
334
+
324
335
@os_helper .skip_unless_symlink
325
336
@unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
326
337
def test_realpath_strict (self ):
Original file line number Diff line number Diff line change
1
+ Fixed a bug where :exc: `TypeError ` was raised when calling
2
+ :func: `ntpath.realpath ` with a bytes parameter in some cases.
You can’t perform that action at this time.
0 commit comments