Skip to content

shlex - non-posix-mode: error in Multiple occurances of quotes substrings/words #72578

Description

@ArnoCan
mannequin
BPO 28392
Nosy @vsajip, @ericvsmith, @ezio-melotti, @merwok, @bitdancer, @ArnoCan

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 2016-10-09.15:02:55.120>
created_at = <Date 2016-10-09.08:02:45.586>
labels = ['invalid', 'type-bug', 'library']
title = 'shlex - non-posix-mode: error in Multiple occurances of quotes substrings/words'
updated_at = <Date 2016-10-09.15:02:55.119>
user = 'https://github.com/ArnoCan'

bugs.python.org fields:

activity = <Date 2016-10-09.15:02:55.119>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2016-10-09.15:02:55.120>
closer = 'r.david.murray'
components = ['Library (Lib)']
creation = <Date 2016-10-09.08:02:45.586>
creator = 'acue'
dependencies = []
files = []
hgrepos = []
issue_num = 28392
keywords = []
message_count = 2.0
messages = ['278351', '278361']
nosy_count = 10.0
nosy_names = ['vinay.sajip', 'eric.smith', 'robodan', 'ezio.melotti', 'eric.araujo', 'r.david.murray', 'cvrebert', 'python-dev', 'Andrey.Kislyuk', 'acue']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue28392'
versions = ['Python 2.7']

Activity

  1. ArnoCan commented on Oct 9, 2016

    ArnoCanmannequin
    MannequinAuthor

    See also 28391: Multiple occurances of: Closing quotes separate words

    The bpo-28391 is accepted, as it is defined:
    Quotes *within* words are ignored, only a leading quoted string will result in a separate word. (That's recursive: try '"Do""This""Separate).

    So I implement for compatibility mode your proposal.

    But the example does not seem to work as expected, so seems to hint to a bug. Thus openning a seperate issue:

    snip-->
    import shlex

    sopts = """-a "Do""This""Separate" """
    resx = ["-a", '"Do"', 'ThisSeparate', ]
    res=shlex.split(sopts,posix=False)

    print "sopts ="+str(sopts)
    print "resx ="+str(resx)
    print "res ="+str(res)
    assert res == resx

    """
    Results in:

    sopts  =-a "Do""This""Separate" 
    resx   =['-a', '"Do"', 'ThisSeparate']
    res    =['-a', '"Do"', '"This"', '"Separate"']
    Traceback (most recent call last):
      File "shlex_demo.py", line 52, in <module>
        assert res == resx 
    AssertionError

    """

    <--snip

    I also checked the variant with a trailing quoted word for completeness, which is not enclosed. Does not split at all:

    sopts =-a Do"SeparateThis"
    resx =['-a', 'Do', '"SeparateThis"']
    res =['-a', 'Do"SeparateThis"']

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Oct 9, 2016
  3. bitdancer commented on Oct 9, 2016

    @bitdancer
    Member
    >>> shlex.split('"Do""This""Separate"', posix=False)
      ['"Do"', '"This"', '"Separate"']
      >>> shlex.split('Do"SeparateThis"', posix=False)
      ['Do"SeparateThis"']

    Both of these are as documented. The first has three separate words, since each word that starts with a leading " is split at the closing quote (thus producing a new word that starts with a "). The last is one word, because the first " is internal to the word that starts at 'Do'.

    In any case, if you find something that disagrees with the docs, we'll just change the docs, because posix=False exists only for backward compatibility so whatever the code actually does is by definition correct at this point.

  4. 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

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions