From: Jesus Cea Date: Thu, 10 May 2012 03:01:11 +0000 (+0200) Subject: Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/' X-Git-Tag: v2.7.4rc1~839 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f2011e3e49a91e613bbe69a198c2b2239cb874a6;p=thirdparty%2FPython%2Fcpython.git Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/' --- diff --git a/Lib/posixpath.py b/Lib/posixpath.py index aae38d5abf3b..163c00c445ca 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 8bb78d66e2fb..957a903e3f74 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 2fb33823edb2..ca9d4f28b666 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 29e6dadaa529..7dbeb9e2292b 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.