From: Jonas Devlieghere Date: Mon, 25 Mar 2019 17:27:14 +0000 (+0000) Subject: [Args] Handle backticks to prevent crash. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7d3225c4b41403856f6a6c6a781025c22cf9f54c;p=platform%2Fupstream%2Fllvm.git [Args] Handle backticks to prevent crash. Currently LLDB crashes when autocompleting a command that ends with a backtick because the quote character wasn't handled. This fixes that and adds a unit test for this function. Differential revision: https://reviews.llvm.org/D59779 llvm-svn: 356927 --- diff --git a/lldb/source/Utility/Args.cpp b/lldb/source/Utility/Args.cpp index 74a56f5..edcbf69 100644 --- a/lldb/source/Utility/Args.cpp +++ b/lldb/source/Utility/Args.cpp @@ -640,14 +640,15 @@ std::string Args::EscapeLLDBCommandArgument(const std::string &arg, case '\0': chars_to_escape = " \t\\'\"`"; break; - case '\'': - chars_to_escape = ""; - break; case '"': chars_to_escape = "$\"`\\"; break; + case '`': + case '\'': + return arg; default: assert(false && "Unhandled quote character"); + return arg; } std::string res; diff --git a/lldb/unittests/Utility/ArgsTest.cpp b/lldb/unittests/Utility/ArgsTest.cpp index ef63ab3..b4bb9ca 100644 --- a/lldb/unittests/Utility/ArgsTest.cpp +++ b/lldb/unittests/Utility/ArgsTest.cpp @@ -188,3 +188,29 @@ TEST(ArgsTest, GetArgumentArrayRef) { EXPECT_STREQ("foo", ref[0]); EXPECT_STREQ("bar", ref[1]); } + +TEST(ArgsTest, EscapeLLDBCommandArgument) { + const std::string foo = "foo'"; + EXPECT_EQ("foo\\'", Args::EscapeLLDBCommandArgument(foo, '\0')); + EXPECT_EQ("foo'", Args::EscapeLLDBCommandArgument(foo, '\'')); + EXPECT_EQ("foo'", Args::EscapeLLDBCommandArgument(foo, '`')); + EXPECT_EQ("foo'", Args::EscapeLLDBCommandArgument(foo, '"')); + + const std::string bar = "bar\""; + EXPECT_EQ("bar\\\"", Args::EscapeLLDBCommandArgument(bar, '\0')); + EXPECT_EQ("bar\"", Args::EscapeLLDBCommandArgument(bar, '\'')); + EXPECT_EQ("bar\"", Args::EscapeLLDBCommandArgument(bar, '`')); + EXPECT_EQ("bar\\\"", Args::EscapeLLDBCommandArgument(bar, '"')); + + const std::string baz = "baz`"; + EXPECT_EQ("baz\\`", Args::EscapeLLDBCommandArgument(baz, '\0')); + EXPECT_EQ("baz`", Args::EscapeLLDBCommandArgument(baz, '\'')); + EXPECT_EQ("baz`", Args::EscapeLLDBCommandArgument(baz, '`')); + EXPECT_EQ("baz\\`", Args::EscapeLLDBCommandArgument(baz, '"')); + + const std::string quux = "quux\t"; + EXPECT_EQ("quux\\\t", Args::EscapeLLDBCommandArgument(quux, '\0')); + EXPECT_EQ("quux\t", Args::EscapeLLDBCommandArgument(quux, '\'')); + EXPECT_EQ("quux\t", Args::EscapeLLDBCommandArgument(quux, '`')); + EXPECT_EQ("quux\t", Args::EscapeLLDBCommandArgument(quux, '"')); +}