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: shlex - non-posix-mode: error in Multiple occurances of quotes substrings/words
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Andrey.Kislyuk, acue, cvrebert, eric.araujo, eric.smith, ezio.melotti, python-dev, r.david.murray, robodan, vinay.sajip
Priority: normal Keywords:

Created on 2016-10-09 08:02 by acue, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg278351 - (view) Author: Arno-Can Uestuensoez (acue) Date: 2016-10-09 08:02
See also 28391: Multiple occurances of: Closing quotes separate words

The issue 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"']
msg278361 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-10-09 15:02
>>> 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.
History
Date User Action Args
2022-04-11 14:58:38adminsetgithub: 72578
2016-10-09 15:02:55r.david.murraysetstatus: open -> closed
resolution: not a bug
messages: + msg278361

stage: resolved
2016-10-09 08:02:45acuecreate