#5471: fix expanduser() for $HOME set to "/".
This commit is contained in:
parent
a7ec0726e2
commit
3f0ef20269
|
@ -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:]
|
||||
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue