]> granicus.if.org Git - python/commitdiff
#5471: fix expanduser() for $HOME set to "/".
authorGeorg Brandl <georg@python.org>
Sun, 5 Apr 2009 14:48:49 +0000 (14:48 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 5 Apr 2009 14:48:49 +0000 (14:48 +0000)
Lib/posixpath.py
Lib/test/test_posixpath.py
Misc/NEWS

index 6eb45fd0eaddbb7e076ceaeaee65bd4aee6027da..0ec430ddf7c41b645c1bbf6905204ab7eb99d000 100644 (file)
@@ -262,7 +262,7 @@ def expanduser(path):
         except KeyError:
             return path
         userhome = pwent.pw_dir
-    userhome = userhome.rstrip('/')
+    userhome = userhome.rstrip('/') or userhome
     return userhome + path[i:]
 
 
index 46ac067263102e2d6f4b2a6f5d5f0e8b26c74eb6..e6f750a0c2ebb4e8dde1d5e0da2c40701e3da8b2 100644 (file)
@@ -345,6 +345,11 @@ class PosixPathTest(unittest.TestCase):
             self.assert_(isinstance(posixpath.expanduser("~root/"), basestring))
             self.assert_(isinstance(posixpath.expanduser("~foo/"), basestring))
 
+            orig_home = os.environ['HOME']
+            os.environ['HOME'] = '/'
+            self.assertEqual(posixpath.expanduser("~"), "/")
+            os.environ['HOME'] = orig_home
+
         self.assertRaises(TypeError, posixpath.expanduser)
 
     def test_expandvars(self):
index bfcd9fa91143010195c12086be79b011bf1ec8df..fd35fad312057ad564bff4a3a7ce386ec4836b8a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -212,6 +212,8 @@ Core and Builtins
 Library
 -------
 
+- Issue 5471: Fix os.path.expanduser() for $HOME set to '/'.
+
 - Issue 1326077: fix the formatting of SyntaxErrors by the traceback module.
 
 - Issue 1726172: fix IndexError in the case of and empty response in ftplib.