diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/posixpath.py | 4 | ||||
-rw-r--r-- | Lib/test/test_posixpath.py | 1 |
2 files changed, 3 insertions, 2 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py index c9829e1..9570a36 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -266,8 +266,8 @@ def expanduser(path): root = b'/' else: root = '/' - userhome = userhome.rstrip(root) or userhome - return userhome + path[i:] + userhome = userhome.rstrip(root) + return (userhome + path[i:]) or root # Expand paths containing shell variable substitutions. diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index bb4559c..a7a3e4a 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -298,6 +298,7 @@ class PosixPathTest(unittest.TestCase): with support.EnvironmentVarGuard() as env: env['HOME'] = '/' self.assertEqual(posixpath.expanduser("~"), "/") + self.assertEqual(posixpath.expanduser("~/foo"), "/foo") # expanduser should fall back to using the password database del env['HOME'] home = pwd.getpwuid(os.getuid()).pw_dir |