This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.expanduser('~') doesnt works correctly when HOME is '/'
Type: behavior Stage:
Components: None Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, gpolo, jcea, pancake
Priority: normal Keywords: patch

Created on 2009-03-10 19:16 by pancake, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue_5471.diff gpolo, 2009-03-10 19:30
Messages (4)
msg83445 - (view) Author: pancake (pancake) Date: 2009-03-10 19:16
When the HOME path is just '/' python says that the home path is ""
(zero length string)

I was able to reproduce this issue in 2.5.2 and 2.6 (no idea about 3.0)

Here's an example:

$ HOME=/ python -c 'import os;print os.path.expanduser("~")'

$ HOME=/tmp python -c 'import os;print os.path.expanduser("~")'
/tmp

$ HOME=a python -c 'import os;print os.path.expanduser("~")'
a

------8<----------

I just used "if !os.path.isdir(os.path.expanduser('~')):" check in
my application to avoid messing around the resulting paths when the
application runs.

The correct response should be '/' instead of ''.
msg83446 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-03-10 19:30
Patch with a test attached.
msg85506 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-04-05 14:49
Thanks, committed in r71241.
msg160323 - (view) Author: Jesús Cea Avión (jcea) * (Python committer) Date: 2012-05-10 02:46
See issue #14768.
History
Date User Action Args
2022-04-11 14:56:46adminsetgithub: 49721
2012-05-10 02:46:35jceasetnosy: + jcea
messages: + msg160323
2009-04-05 14:49:01georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg85506

resolution: accepted
2009-03-10 19:30:19gpolosetfiles: + issue_5471.diff
versions: + Python 3.0, Python 3.1, Python 2.7
nosy: + gpolo

messages: + msg83446

keywords: + patch
2009-03-10 19:16:14pancakecreate