Commit f2011e3e authored by Jesus Cea's avatar Jesus Cea

Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'

parent 95f42a86
...@@ -267,8 +267,8 @@ def expanduser(path): ...@@ -267,8 +267,8 @@ def expanduser(path):
except KeyError: except KeyError:
return path return path
userhome = pwent.pw_dir userhome = pwent.pw_dir
userhome = userhome.rstrip('/') or userhome userhome = userhome.rstrip('/')
return userhome + path[i:] return (userhome + path[i:]) or '/'
# Expand paths containing shell variable substitutions. # Expand paths containing shell variable substitutions.
......
...@@ -201,6 +201,7 @@ class PosixPathTest(unittest.TestCase): ...@@ -201,6 +201,7 @@ class PosixPathTest(unittest.TestCase):
with test_support.EnvironmentVarGuard() as env: with test_support.EnvironmentVarGuard() as env:
env['HOME'] = '/' env['HOME'] = '/'
self.assertEqual(posixpath.expanduser("~"), "/") self.assertEqual(posixpath.expanduser("~"), "/")
self.assertEqual(posixpath.expanduser("~/foo"), "/foo")
def test_normpath(self): def test_normpath(self):
self.assertEqual(posixpath.normpath(""), ".") self.assertEqual(posixpath.normpath(""), ".")
......
...@@ -274,6 +274,7 @@ Doug Fort ...@@ -274,6 +274,7 @@ Doug Fort
John Fouhy John Fouhy
Martin Franklin Martin Franklin
Robin Friedrich Robin Friedrich
Bradley Froehle
Ivan Frohne Ivan Frohne
Jim Fulton Jim Fulton
Tadayoshi Funaba Tadayoshi Funaba
......
...@@ -60,6 +60,8 @@ Core and Builtins ...@@ -60,6 +60,8 @@ Core and Builtins
Library Library
------- -------
- Issue #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'.
- Issue #13183: Fix pdb skipping frames after hitting a breakpoint and running - Issue #13183: Fix pdb skipping frames after hitting a breakpoint and running
step. Patch by Xavier de Gaye. step. Patch by Xavier de Gaye.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment