#5471: fix expanduser() for $HOME set to "/".

This commit is contained in:
Georg Brandl 2009-04-05 14:48:49 +00:00
parent a7ec0726e2
commit 3f0ef20269
3 changed files with 8 additions and 1 deletions

View File

@ -262,7 +262,7 @@ def expanduser(path):
except KeyError:
return path
userhome = pwent.pw_dir
userhome = userhome.rstrip('/')
userhome = userhome.rstrip('/') or userhome
return userhome + path[i:]

View File

@ -345,6 +345,11 @@ class PosixPathTest(unittest.TestCase):
self.assert_(isinstance(posixpath.expanduser("~root/"), basestring))
self.assert_(isinstance(posixpath.expanduser("~foo/"), basestring))
orig_home = os.environ['HOME']
os.environ['HOME'] = '/'
self.assertEqual(posixpath.expanduser("~"), "/")
os.environ['HOME'] = orig_home
self.assertRaises(TypeError, posixpath.expanduser)
def test_expandvars(self):

View File

@ -212,6 +212,8 @@ Core and Builtins
Library
-------
- Issue 5471: Fix os.path.expanduser() for $HOME set to '/'.
- Issue 1326077: fix the formatting of SyntaxErrors by the traceback module.
- Issue 1726172: fix IndexError in the case of and empty response in ftplib.