]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'
authorJesus Cea <jcea@jcea.es>
Thu, 10 May 2012 03:01:11 +0000 (05:01 +0200)
committerJesus Cea <jcea@jcea.es>
Thu, 10 May 2012 03:01:11 +0000 (05:01 +0200)
Lib/posixpath.py
Lib/test/test_posixpath.py
Misc/ACKS
Misc/NEWS

index aae38d5abf3bc7e5a81270eca8067b3cca05ddef..163c00c445ca1233165ef124c2b2cf7ee701a73d 100644 (file)
@@ -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.
index 8bb78d66e2fbff69839547904b1a18dbac71a310..957a903e3f7440e20a08b585f48aa1dd8a0cf8e5 100644 (file)
@@ -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(""), ".")
index 2fb33823edb26012ff7522eec56c73b44d5d5161..ca9d4f28b666ca040aefa0012672953031393d5e 100644 (file)
--- 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
index 29e6dadaa529a1a648274b4412f83f1d4208ad2e..7dbeb9e2292ba5a0dedd11083c06f12640b3afed 100644 (file)
--- 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.