File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -414,7 +414,7 @@ def realpath(filename):
414414 if isabs (filename ):
415415 bits = ['/' ] + filename .split ('/' )[1 :]
416416 else :
417- bits = filename .split ('/' )
417+ bits = [ '' ] + filename .split ('/' )
418418
419419 for i in range (2 , len (bits )+ 1 ):
420420 component = join (* bits [0 :i ])
Original file line number Diff line number Diff line change @@ -476,6 +476,26 @@ def test_realpath_resolve_before_normalizing(self):
476476 self .safe_rmdir (ABSTFN + "/k/y" )
477477 self .safe_rmdir (ABSTFN + "/k" )
478478 self .safe_rmdir (ABSTFN )
479+
480+ def test_realpath_resolve_first (self ):
481+ # Bug #1213894: The first component of the path, if not absolute,
482+ # must be resolved too.
483+
484+ try :
485+ old_path = abspath ('.' )
486+ os .mkdir (ABSTFN )
487+ os .mkdir (ABSTFN + "/k" )
488+ os .symlink (ABSTFN , ABSTFN + "link" )
489+ os .chdir (dirname (ABSTFN ))
490+
491+ base = basename (ABSTFN )
492+ self .assertEqual (realpath (base + "link" ), ABSTFN )
493+ self .assertEqual (realpath (base + "link/k" ), ABSTFN + "/k" )
494+ finally :
495+ os .chdir (old_path )
496+ self .safe_remove (ABSTFN + "link" )
497+ self .safe_rmdir (ABSTFN + "/k" )
498+ self .safe_rmdir (ABSTFN )
479499
480500 # Convenience functions for removing temporary files.
481501 def pass_os_error (self , func , filename ):
Original file line number Diff line number Diff line change @@ -136,6 +136,9 @@ Extension Modules
136136Library
137137-------
138138
139+ - Bug #1213894: os.path.realpath didn't resolve symlinks that were the first
140+ component of the path.
141+
139142- Patch #1120353: The xmlrpclib module provides better, more transparent,
140143 support for datetime.{datetime,date,time} objects. With use_datetime set
141144 to True, applications shouldn't have to fiddle with the DateTime wrapper
You can’t perform that action at this time.
0 commit comments