File tree Expand file tree Collapse file tree 3 files changed +8
-1
lines changed
Expand file tree Collapse file tree 3 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -262,7 +262,7 @@ def expanduser(path):
262262 except KeyError :
263263 return path
264264 userhome = pwent .pw_dir
265- userhome = userhome .rstrip ('/' )
265+ userhome = userhome .rstrip ('/' ) or userhome
266266 return userhome + path [i :]
267267
268268
Original file line number Diff line number Diff line change @@ -345,6 +345,11 @@ def test_expanduser(self):
345345 self .assert_ (isinstance (posixpath .expanduser ("~root/" ), basestring ))
346346 self .assert_ (isinstance (posixpath .expanduser ("~foo/" ), basestring ))
347347
348+ orig_home = os .environ ['HOME' ]
349+ os .environ ['HOME' ] = '/'
350+ self .assertEqual (posixpath .expanduser ("~" ), "/" )
351+ os .environ ['HOME' ] = orig_home
352+
348353 self .assertRaises (TypeError , posixpath .expanduser )
349354
350355 def test_expandvars (self ):
Original file line number Diff line number Diff line change @@ -212,6 +212,8 @@ Core and Builtins
212212Library
213213-------
214214
215+ - Issue 5471: Fix os.path.expanduser() for $HOME set to '/'.
216+
215217- Issue 1326077: fix the formatting of SyntaxErrors by the traceback module.
216218
217219- Issue 1726172: fix IndexError in the case of and empty response in ftplib.
You can’t perform that action at this time.
0 commit comments