mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'
This commit is contained in:
parent
d576c711a5
commit
7f0d88860f
4 changed files with 6 additions and 2 deletions
|
@ -266,8 +266,8 @@ def expanduser(path):
|
||||||
root = b'/'
|
root = b'/'
|
||||||
else:
|
else:
|
||||||
root = '/'
|
root = '/'
|
||||||
userhome = userhome.rstrip(root) or userhome
|
userhome = userhome.rstrip(root)
|
||||||
return userhome + path[i:]
|
return (userhome + path[i:]) or root
|
||||||
|
|
||||||
|
|
||||||
# Expand paths containing shell variable substitutions.
|
# Expand paths containing shell variable substitutions.
|
||||||
|
|
|
@ -298,6 +298,7 @@ class PosixPathTest(unittest.TestCase):
|
||||||
with support.EnvironmentVarGuard() as env:
|
with support.EnvironmentVarGuard() as env:
|
||||||
env['HOME'] = '/'
|
env['HOME'] = '/'
|
||||||
self.assertEqual(posixpath.expanduser("~"), "/")
|
self.assertEqual(posixpath.expanduser("~"), "/")
|
||||||
|
self.assertEqual(posixpath.expanduser("~/foo"), "/foo")
|
||||||
# expanduser should fall back to using the password database
|
# expanduser should fall back to using the password database
|
||||||
del env['HOME']
|
del env['HOME']
|
||||||
home = pwd.getpwuid(os.getuid()).pw_dir
|
home = pwd.getpwuid(os.getuid()).pw_dir
|
||||||
|
|
|
@ -308,6 +308,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
|
||||||
|
|
|
@ -63,6 +63,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'.
|
||||||
|
|
||||||
- Issue #14741: Fix missing support for Ellipsis ('...') in parser module.
|
- Issue #14741: Fix missing support for Ellipsis ('...') in parser module.
|
||||||
|
|
||||||
- Issue #14697: Fix missing support for set displays and set comprehensions in
|
- Issue #14697: Fix missing support for set displays and set comprehensions in
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue