Commits

Jesús Cea committed e472481

Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'

  • Participants
  • Parent commits 9de4d85
  • Branches 3.2

Comments (0)

Files changed (4)

File Lib/posixpath.py

         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.

File Lib/test/test_posixpath.py

             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
 John Fouhy
 Martin Franklin
 Robin Friedrich
+Bradley Froehle
 Ivan Frohne
 Jim Fulton
 Tadayoshi Funaba
 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