Index: lldb/source/Utility/Args.cpp =================================================================== --- lldb/source/Utility/Args.cpp +++ lldb/source/Utility/Args.cpp @@ -384,9 +384,9 @@ llvm::StringRef m_escapables; }; - static ShellDescriptor g_Shells[] = {{ConstString("bash"), " '\"<>()&"}, - {ConstString("tcsh"), " '\"<>()&$"}, - {ConstString("sh"), " '\"<>()&"}}; + static ShellDescriptor g_Shells[] = {{ConstString("bash"), " '\"<>()&;"}, + {ConstString("tcsh"), " '\"<>()&$;"}, + {ConstString("sh"), " '\"<>()&;"}}; // safe minimal set llvm::StringRef escapables = " '\""; Index: lldb/unittests/Utility/ArgsTest.cpp =================================================================== --- lldb/unittests/Utility/ArgsTest.cpp +++ lldb/unittests/Utility/ArgsTest.cpp @@ -322,14 +322,25 @@ EXPECT_EQ(Args::GetShellSafeArgument(bash, "a\""), "a\\\""); EXPECT_EQ(Args::GetShellSafeArgument(bash, "a\"b"), "a\\\"b"); - // 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);