From f2011e3e49a91e613bbe69a198c2b2239cb874a6 Mon Sep 17 00:00:00 2001 From: Jesus Cea Date: Thu, 10 May 2012 05:01:11 +0200 Subject: [PATCH] Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/' --- Lib/posixpath.py | 4 ++-- Lib/test/test_posixpath.py | 1 + Misc/ACKS | 1 + Misc/NEWS | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/posixpath.py b/Lib/posixpath.py index aae38d5abf3..163c00c445c 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -267,8 +267,8 @@ def expanduser(path): 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 8bb78d66e2f..957a903e3f7 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -201,6 +201,7 @@ class PosixPathTest(unittest.TestCase): 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 2fb33823edb..ca9d4f28b66 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -274,6 +274,7 @@ Doug Fort John Fouhy Martin Franklin Robin Friedrich +Bradley Froehle Ivan Frohne Jim Fulton Tadayoshi Funaba diff --git a/Misc/NEWS b/Misc/NEWS index 29e6dadaa52..7dbeb9e2292 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -60,6 +60,8 @@ Core and Builtins 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.