[issue36897] shlex doesn't differentiate escaped characters in output

Eric V. Smith report at bugs.python.org
Mon May 13 20:38:57 EDT 2019


Eric V. Smith <eric at trueblade.com> added the comment:

Run 3.7 with -Wd:

$ python3 -Wd
Python 3.7.3 (default, Mar 29 2019, 13:03:53)
[GCC 7.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 'a \; b'
<stdin>:1: DeprecationWarning: invalid escape sequence \;
'a \\; b'
>>>

The deprecation is in relation to invalid escape sequences, not shlex.

My point is just that you should use r'a \; b' or 'a \\;b', and not rely on invalid escape sequences. For one reason, I can never remember how they're interpreted, and had to look it up. r-strings don't have anything to do with regular expressions per-se, they're a way of changing how python interprets stings, no matter what they're used for.

> The point is that it's not possible to use the output of shlex.shlex to try to match the behaviour of a POSIX-compliant shell by reliably splitting up a user's input into multiple commands. In the first case I presented (no escape character), the user entered two commands. In the second case, the user entered a single command with two arguments. However, there's no way to differentiate the two situations based on the output of shlex.

My question is: can a posix-compliant shell tell the difference? I don't know, it's an honest question. Can you show some shell code where it can tell the difference?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36897>
_______________________________________


More information about the Python-bugs-list mailing list