diff options
author | kotfu <kotfu@kotfu.net> | 2018-09-09 21:09:08 -0600 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-09-09 21:09:08 -0600 |
commit | caa3c4e1da22ca8f4b9086c1bc0e3fe3010a95ab (patch) | |
tree | dd8e94bf574212c43b36f5e7009646581f92ac48 /cmd2 | |
parent | 0e8ab46adfbeac86291899115a28a36f6eb066bc (diff) | |
download | cmd2-git-caa3c4e1da22ca8f4b9086c1bc0e3fe3010a95ab.tar.gz |
Fix bug in `parse_command_only`
More robust unit tests identified a bug, which is also fixed in this commit.
Diffstat (limited to 'cmd2')
-rw-r--r-- | cmd2/parsing.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py index 61b6f745..8edfacb9 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -452,13 +452,16 @@ class StatementParser: This method is used by tab completion code and therefore must not generate an exception if there are unclosed quotes. - The Statement object returned by this method can at most contain values + The `Statement` object returned by this method can at most contain values in the following attributes: - args - raw - command - multiline_command + `Statement.args` includes all output redirection clauses and command + terminators. + Different from parse(), this method does not remove redundant whitespace within args. However, it does ensure args has no leading or trailing whitespace. @@ -473,12 +476,10 @@ class StatementParser: # we got a match, extract the command command = match.group(1) - # the _command_pattern regex is designed to match the spaces - # between command and args with a second match group. Using - # the end of the second match group ensures that args has - # no leading whitespace. The rstrip() makes sure there is - # no trailing whitespace - args = line[match.end(2):].rstrip() + # take everything from the end of the first match group to + # the end of the line as the arguments (stripping leading + # and trailing spaces) + args = line[match.end(1):].strip() # if the command is empty that means the input was either empty # or something weird like '>'. args should be empty if we couldn't # parse a command |