diff --git a/lldb/source/Utility/Args.cpp b/lldb/source/Utility/Args.cpp --- a/lldb/source/Utility/Args.cpp +++ b/lldb/source/Utility/Args.cpp @@ -384,10 +384,10 @@ llvm::StringRef m_escapables; }; - static ShellDescriptor g_Shells[] = {{ConstString("bash"), " '\"<>()&"}, - {ConstString("tcsh"), " '\"<>()&$"}, + static ShellDescriptor g_Shells[] = {{ConstString("bash"), " '\"<>()&;"}, + {ConstString("tcsh"), " '\"<>()&$;"}, {ConstString("zsh"), " '\"<>()&;\\|"}, - {ConstString("sh"), " '\"<>()&"}}; + {ConstString("sh"), " '\"<>()&;"}}; // safe minimal set llvm::StringRef escapables = " '\""; diff --git a/lldb/unittests/Utility/ArgsTest.cpp b/lldb/unittests/Utility/ArgsTest.cpp --- a/lldb/unittests/Utility/ArgsTest.cpp +++ b/lldb/unittests/Utility/ArgsTest.cpp @@ -328,14 +328,25 @@ // Normal characters and expressions that shouldn't be escaped. EXPECT_EQ(Args::GetShellSafeArgument(zsh, "aA$1*"), "aA$1*"); - // String that doesn't need to be escaped - EXPECT_EQ(Args::GetShellSafeArgument(bash, "a"), "a"); + // Test escaping bash special characters. + EXPECT_EQ(Args::GetShellSafeArgument(bash, R"( '"<>()&;)"), + R"(\ \'\"\<\>\(\)\&\;)"); + // Normal characters and globbing expressions that shouldn't be escaped. + EXPECT_EQ(Args::GetShellSafeArgument(bash, "aA$1*"), "aA$1*"); - // Try escaping with tcsh and the tcsh-specific "$" escape. + // Test escaping tcsh special characters. FileSpec tcsh("/bin/tcsh", FileSpec::Style::posix); - EXPECT_EQ(Args::GetShellSafeArgument(tcsh, "a$b"), "a\\$b"); - // Bash however doesn't need escaping for "$". - EXPECT_EQ(Args::GetShellSafeArgument(bash, "a$b"), "a$b"); + EXPECT_EQ(Args::GetShellSafeArgument(tcsh, R"( '"<>()&$;)"), + R"(\ \'\"\<\>\(\)\&\$\;)"); + // Normal characters and globbing expressions that shouldn't be escaped. + EXPECT_EQ(Args::GetShellSafeArgument(tcsh, "aA1*"), "aA1*"); + + // Test escaping sh special characters. + FileSpec sh("/bin/sh", FileSpec::Style::posix); + EXPECT_EQ(Args::GetShellSafeArgument(sh, R"( '"<>()&;)"), + R"(\ \'\"\<\>\(\)\&\;)"); + // Normal characters and globbing expressions that shouldn't be escaped. + EXPECT_EQ(Args::GetShellSafeArgument(sh, "aA$1*"), "aA$1*"); // Try escaping with an unknown shell. FileSpec unknown_shell("/bin/unknown_shell", FileSpec::Style::posix);