diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/posixpath.py | 2 | ||||
-rw-r--r-- | Lib/test/test_posixpath.py | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 6eb45fd..0ec430d 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -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:] diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 46ac067..e6f750a 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -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): |