Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environ doesn't escape spaces properly #49348

Closed
stuaxo mannequin opened this issue Jan 29, 2009 · 3 comments
Closed

Environ doesn't escape spaces properly #49348

stuaxo mannequin opened this issue Jan 29, 2009 · 3 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@stuaxo
Copy link
Mannequin

stuaxo mannequin commented Jan 29, 2009

BPO 5098
Nosy @loewis

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-01-29.19:22:38.899>
created_at = <Date 2009-01-29.14:41:56.584>
labels = ['type-bug', 'invalid']
title = "Environ doesn't escape spaces properly"
updated_at = <Date 2009-01-29.19:22:38.815>
user = 'https://bugs.python.org/stuaxo'

bugs.python.org fields:

activity = <Date 2009-01-29.19:22:38.815>
actor = 'loewis'
assignee = 'none'
closed = True
closed_date = <Date 2009-01-29.19:22:38.899>
closer = 'loewis'
components = ['None']
creation = <Date 2009-01-29.14:41:56.584>
creator = 'stuaxo'
dependencies = []
files = []
hgrepos = []
issue_num = 5098
keywords = []
message_count = 3.0
messages = ['80765', '80767', '80779']
nosy_count = 3.0
nosy_names = ['loewis', 'exarkun', 'stuaxo']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue5098'
versions = ['Python 2.5']

@stuaxo
Copy link
Mannequin Author

stuaxo mannequin commented Jan 29, 2009

os.environ doesn't escape spaces, but does backslashes and others

In the windows python interpreter I echo'd the variable 'ProgramFiles',
then in the commandprompt.

>>> from os import environ
>>> environ['ProgramFiles']
'C:\\Program Files'
>>> ^Z

[C:\]echo %ProgramFiles%
C:\Program Files

This 'half' escapping seems odd, and is annoying when building file
paths for instance, probably the space should also be escaped.

@stuaxo stuaxo mannequin added the type-bug An unexpected behavior, bug, or error label Jan 29, 2009
@exarkun
Copy link
Mannequin

exarkun mannequin commented Jan 29, 2009

The backslash escaping has nothing to do with os.environ. It's the way
any string with a backslash in it is displayed in the interactive
interpreter (it's the way str.__repr__ works). Performing any escaping
on a string to make it usable in a command line is a task which is
inappropriate as a feature of os.environ. The contents of os.environ
are just strings. If you want to use them in a command line, you need
to escape them appropriately. Notice that in addition to escaping the
space, you may also sometimes need to escape a backslash (not in this
case on Windows, though, since a single \ is allowed here). The
escaping of the \ in this example is *only* in the *display* of the
variable - there is only one \ in the string itself.

I recommend closing this ticket as invalid.

@loewis
Copy link
Mannequin

loewis mannequin commented Jan 29, 2009

As Jean-Paul explains, you are misinterpreting what you are seeing.
Closing as invalid.

@loewis loewis mannequin closed this as completed Jan 29, 2009
@loewis loewis mannequin added the invalid label Jan 29, 2009
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants