Skip to content

Environ doesn't escape spaces properly #49348

Closed

Description

@stuaxo
mannequin
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']

Activity

  1. stuaxo commented on Jan 29, 2009

    stuaxomannequin
    MannequinAuthor

    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.

  2. added
    type-bug
    on Jan 29, 2009
  3. exarkun commented on Jan 29, 2009

    exarkunmannequin
    Mannequin

    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.

  4. loewis commented on Jan 29, 2009

    loewismannequin
    Mannequin

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

  5. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions