Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index aae38d5..163c00c 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -267,8 +267,8 @@
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.
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index 8bb78d6..957a903 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -201,6 +201,7 @@
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(""), ".")
diff --git a/Misc/ACKS b/Misc/ACKS
index 2fb3382..ca9d4f2 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -274,6 +274,7 @@
John Fouhy
Martin Franklin
Robin Friedrich
+Bradley Froehle
Ivan Frohne
Jim Fulton
Tadayoshi Funaba
diff --git a/Misc/NEWS b/Misc/NEWS
index 29e6dad..7dbeb9e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,8 @@
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
step. Patch by Xavier de Gaye.