Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b58ab2c

Browse files
committed
MERGE: Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'
2 parents 3b1a74a + 7f0d888 commit b58ab2c

4 files changed

Lines changed: 6 additions & 2 deletions

File tree

Lib/posixpath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ def expanduser(path):
266266
root = b'/'
267267
else:
268268
root = '/'
269-
userhome = userhome.rstrip(root) or userhome
270-
return userhome + path[i:]
269+
userhome = userhome.rstrip(root)
270+
return (userhome + path[i:]) or root
271271

272272

273273
# Expand paths containing shell variable substitutions.

Lib/test/test_posixpath.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def test_expanduser(self):
300300
with support.EnvironmentVarGuard() as env:
301301
env['HOME'] = '/'
302302
self.assertEqual(posixpath.expanduser("~"), "/")
303+
self.assertEqual(posixpath.expanduser("~/foo"), "/foo")
303304
# expanduser should fall back to using the password database
304305
del env['HOME']
305306
home = pwd.getpwuid(os.getuid()).pw_dir

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ Andrew Francis
335335
Martin Franklin
336336
Bruce Frederiksen
337337
Robin Friedrich
338+
Bradley Froehle
338339
Ivan Frohne
339340
Matthias Fuchs
340341
Jim Fulton

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ Library
139139

140140
- Issue #13815: TarFile.extractfile() now returns io.BufferedReader objects.
141141

142+
- Issue #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'.
143+
142144
- Issue #14371: Support bzip2 in zipfile module. Patch by Serhiy Storchaka.
143145

144146
- Issue #13183: Fix pdb skipping frames after hitting a breakpoint and running

0 commit comments

Comments
 (0)