[Python-checkins] cpython (merge 3.2 -> default): MERGE: Closes #14768: os.path.expanduser('~/a') doesn't works correctly when

jesus.cea python-checkins at python.org
Thu May 10 05:17:00 CEST 2012


http://hg.python.org/cpython/rev/ce39a4ec2906
changeset:   76854:ce39a4ec2906
parent:      76851:0d9067cde462
parent:      76852:e472481b6d73
user:        Jesus Cea <jcea at jcea.es>
date:        Thu May 10 05:16:41 2012 +0200
summary:
  MERGE: Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'

files:
  Lib/posixpath.py           |  4 ++--
  Lib/test/test_posixpath.py |  1 +
  Misc/ACKS                  |  1 +
  Misc/NEWS                  |  2 ++
  4 files changed, 6 insertions(+), 2 deletions(-)


diff --git a/Lib/posixpath.py b/Lib/posixpath.py
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -266,8 +266,8 @@
         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.
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -300,6 +300,7 @@
             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
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -335,6 +335,7 @@
 Martin Franklin
 Bruce Frederiksen
 Robin Friedrich
+Bradley Froehle
 Ivan Frohne
 Matthias Fuchs
 Jim Fulton
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -139,6 +139,8 @@
 
 - Issue #13815: TarFile.extractfile() now returns io.BufferedReader objects.
 
+- Issue #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'.
+
 - Issue #14371: Support bzip2 in zipfile module.  Patch by Serhiy Storchaka.
 
 - Issue #13183: Fix pdb skipping frames after hitting a breakpoint and running

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list