diff -r d3ddbad31b3e Lib/posixpath.py --- a/Lib/posixpath.py Wed May 09 14:59:24 2012 +0300 +++ b/Lib/posixpath.py Wed May 09 19:46:49 2012 -0700 @@ -267,8 +267,8 @@ 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 -r d3ddbad31b3e Lib/test/test_posixpath.py --- a/Lib/test/test_posixpath.py Wed May 09 14:59:24 2012 +0300 +++ b/Lib/test/test_posixpath.py Wed May 09 19:46:49 2012 -0700 @@ -201,6 +201,7 @@ 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(""), ".")