mirror of https://github.com/python/cpython
Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'
This commit is contained in:
parent
95f42a86dd
commit
f2011e3e49
|
@ -267,8 +267,8 @@ def expanduser(path):
|
|||
except KeyError:
|
||||
return path
|
||||
userhome = pwent.pw_dir
|
||||
userhome = userhome.rstrip('/') or userhome
|
||||
return userhome + path[i:]
|
||||
userhome = userhome.rstrip('/')
|
||||
return (userhome + path[i:]) or '/'
|
||||
|
||||
|
||||
# Expand paths containing shell variable substitutions.
|
||||
|
|
|
@ -201,6 +201,7 @@ class PosixPathTest(unittest.TestCase):
|
|||
with test_support.EnvironmentVarGuard() as env:
|
||||
env['HOME'] = '/'
|
||||
self.assertEqual(posixpath.expanduser("~"), "/")
|
||||
self.assertEqual(posixpath.expanduser("~/foo"), "/foo")
|
||||
|
||||
def test_normpath(self):
|
||||
self.assertEqual(posixpath.normpath(""), ".")
|
||||
|
|
|
@ -274,6 +274,7 @@ Doug Fort
|
|||
John Fouhy
|
||||
Martin Franklin
|
||||
Robin Friedrich
|
||||
Bradley Froehle
|
||||
Ivan Frohne
|
||||
Jim Fulton
|
||||
Tadayoshi Funaba
|
||||
|
|
Loading…
Reference in New Issue