classification
Title: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jcea Nosy List: bfroehle, jcea, python-dev
Priority: normal Keywords: easy, patch

Created on 2012-05-10 02:25 by bfroehle, last changed 2012-05-10 03:16 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
issue_14768.patch bfroehle, 2012-05-10 02:50 review
Messages (4)
msg160321 - (view) Author: Bradley Froehle (bfroehle) * Date: 2012-05-10 02:25
When $HOME=/, os.path.expanduser('~/a') returns '//a' rather than '/a'.

This regression was created by a partially incorrect resolution to issue #5471, and affects versions 2.7 and 3.2 (at least).

$ HOME=/ python2.7 -c "import os; print os.path.expanduser('~/a')"
//a
$ HOME=/ python3.2 -c "import os; print(os.path.expanduser('~/a'))"
//a

In each case the expected result should be '/a'.
msg160324 - (view) Author: Jesús Cea Avión (jcea) * (Python committer) Date: 2012-05-10 02:48
I though that this situation would be happen for ANY env with $HOME ending in "/", but it is not the case:

"""
jcea@ubuntu:~$ echo $HOME
/home/jcea
jcea@ubuntu:~$ python
Python 2.7.3 (default, Apr 12 2012, 13:11:53) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.expanduser("~/a")
'/home/jcea/a'


jcea@ubuntu:/home/jcea$ export HOME=/home/jcea/
jcea@ubuntu:/home/jcea$ echo $HOME
/home/jcea/
jcea@ubuntu:/home/jcea$ python
Python 2.7.3 (default, Apr 12 2012, 13:11:53) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.expanduser("~/a")
'/home/jcea/a'
"""

Bradley, would you mind to write a patch & test?
msg160325 - (view) Author: Bradley Froehle (bfroehle) * Date: 2012-05-10 02:50
Patch (for version 2.7) attached.
msg160326 - (view) Author: Roundup Robot (python-dev) Date: 2012-05-10 03:16
New changeset e472481b6d73 by Jesus Cea in branch '3.2':
Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'
http://hg.python.org/cpython/rev/e472481b6d73

New changeset 299dc54ad014 by Jesus Cea in branch '2.7':
Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'
http://hg.python.org/cpython/rev/299dc54ad014

New changeset ce39a4ec2906 by Jesus Cea in branch 'default':
MERGE: Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'
http://hg.python.org/cpython/rev/ce39a4ec2906
History
Date User Action Args
2012-05-10 03:16:59python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg160326

resolution: fixed
stage: resolved
2012-05-10 03:00:36jceasetassignee: jcea
2012-05-10 02:50:34bfroehlesetfiles: + issue_14768.patch
keywords: + patch
messages: + msg160325
2012-05-10 02:48:44jceasetkeywords: + easy
2012-05-10 02:48:31jceasetnosy: + jcea

messages: + msg160324
versions: + Python 3.3
2012-05-10 02:25:19bfroehlecreate