[Lldb-commits] [PATCH] Fix handling of backslashes in Args parsing

Pavel Labath labath at google.com
Tue Feb 24 03:10:08 PST 2015


Hi clayborg,

Presently Args::SetCommandString allows quotes to be escaped with backslash. However, the
backslash itself is not removed from the argument, nor there is a way to escape the backslash
itself. This leads to surprising results:

"a b" c"   -> 'a b', 'c'  # Here we actually have an unterminated quote, but that is ignored
"a b\" c"  -> 'a b\" c'   # We try to escape the quote. That works but the backslash is not removed.
"a b\\" c" -> 'a b\\" c'  # Escaping the backslash has no effect.

This change removes the possibility to escape the terminating quotes, making every quote run from
one quote character to the next one. The contents for the quote are always taken literally, just
like the single quotes in a posix shell. The only way to insert a literal quote character is to
close the quote and then escape it with a backslash or to use a different kind of quotes.

To summarize:
"a b" c"    -> 'a b', 'c'   # unterminated quotes are still ignored
"a b"\"" c" -> 'a b" c'     # first way to insert a literal quote
'a b" c'    -> 'a b" c'     # second way to insert a literal quote
"a b\" c    -> 'a b\', c    # backslash has no effect, we still get two arguments
"a b\\" c   -> 'a b\\', c   # same here

This change also removes some dead quote-handling code. This code (branching on the value of
quote_char) was never executed since all quote handling was concentrated in the case '"': block,
and the value was always set to 0 after exiting the block.

http://reviews.llvm.org/D7855

Files:
  source/Interpreter/Args.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7855.20587.patch
Type: text/x-patch
Size: 5775 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150224/2e37b97d/attachment.bin>


More information about the lldb-commits mailing list