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

index c9829e18d04c4a64664487fecd8da110497788db..9570a364a00398361a46aa5dbdcd6ab4fd660c09 100644 (file)
@@ -266,8 +266,8 @@ def expanduser(path):
         root = b'/'
     else:
         root = '/'
-    userhome = userhome.rstrip(root) or userhome
-    return userhome + path[i:]
+    userhome = userhome.rstrip(root)
+    return (userhome + path[i:]) or root
 
 
 # Expand paths containing shell variable substitutions.
index bb4559c4abd43bb2a3441ef8dd6a5bd04dcb481e..a7a3e4aa12d0ead217e7f3fdbc23724cdf39c78a 100644 (file)
@@ -298,6 +298,7 @@ class PosixPathTest(unittest.TestCase):
             with support.EnvironmentVarGuard() as env:
                 env['HOME'] = '/'
                 self.assertEqual(posixpath.expanduser("~"), "/")
+                self.assertEqual(posixpath.expanduser("~/foo"), "/foo")
                 # expanduser should fall back to using the password database
                 del env['HOME']
                 home = pwd.getpwuid(os.getuid()).pw_dir
index 6d8b6dddd293f26f6f1567c2a5cffdaf5d899fbd..780c06fd5e9c47ea973e21eb378578644c8a5a0a 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -308,6 +308,7 @@ Doug Fort
 John Fouhy
 Martin Franklin
 Robin Friedrich
+Bradley Froehle
 Ivan Frohne
 Jim Fulton
 Tadayoshi Funaba
index b6bc463a5d2fa91aa41594bb5dc7bbda915e2188..c4901b02a78cc0f8a08c7f963f73ebf2c6283465 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -63,6 +63,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'.
+
 - Issue #14741: Fix missing support for Ellipsis ('...') in parser module.
 
 - Issue #14697: Fix missing support for set displays and set comprehensions in