summaryrefslogtreecommitdiff
path: root/source/core/windows/slang-win-process-util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/windows/slang-win-process-util.cpp')
-rw-r--r--source/core/windows/slang-win-process-util.cpp50
1 files changed, 11 insertions, 39 deletions
diff --git a/source/core/windows/slang-win-process-util.cpp b/source/core/windows/slang-win-process-util.cpp
index 3a5a01cb3..9cc567318 100644
--- a/source/core/windows/slang-win-process-util.cpp
+++ b/source/core/windows/slang-win-process-util.cpp
@@ -2,6 +2,7 @@
#include "../slang-process-util.h"
#include "../slang-string.h"
+#include "../slang-string-escape-util.h"
#ifdef _WIN32
// Include Windows header in a way that minimized namespace pollution.
@@ -148,58 +149,29 @@ static DWORD WINAPI _readerThreadProc(LPVOID threadParam)
return 0;
}
-
-/* static */UnownedStringSlice ProcessUtil::getExecutableSuffix()
+/* static */StringEscapeHandler* ProcessUtil::getEscapeHandler()
{
- return UnownedStringSlice::fromLiteral(".exe");
+ return StringEscapeUtil::getHandler(StringEscapeUtil::Style::Space);
}
-/* static */void ProcessUtil::appendCommandLineEscaped(const UnownedStringSlice& slice, StringBuilder& out)
+/* static */UnownedStringSlice ProcessUtil::getExecutableSuffix()
{
- // TODO(JS): This escaping is not complete... !
-
- if ((slice.indexOf(' ') >= 0 || slice.indexOf('"') >= 0))
- {
- out << "\"";
-
- const char* cur = slice.begin();
- const char* end = slice.end();
-
- while (cur < end)
- {
- char c = *cur++;
- switch (c)
- {
- case '\"':
- {
- // Escape quotes.
- out << "\\\"";
- break;
- }
- default:
- out.append(c);
- }
- }
-
- out << "\"";
- return;
- }
- else
- {
- out << slice;
- }
+ return UnownedStringSlice::fromLiteral(".exe");
}
/* static */String ProcessUtil::getCommandLineString(const CommandLine& commandLine)
{
+ auto escapeHandler = getEscapeHandler();
+
StringBuilder cmd;
- appendCommandLineEscaped(commandLine.m_executable.getUnownedSlice(), cmd);
+ StringEscapeUtil::appendMaybeQuoted(escapeHandler, commandLine.m_executable.getUnownedSlice(), cmd);
+
for (const auto& arg : commandLine.m_args)
{
cmd << " ";
if (arg.type == CommandLine::ArgType::Unescaped)
{
- appendCommandLineEscaped(arg.value.getUnownedSlice(), cmd);
+ StringEscapeUtil::appendMaybeQuoted(escapeHandler, arg.value.getUnownedSlice(), cmd);
}
else
{
@@ -269,7 +241,7 @@ static DWORD WINAPI _readerThreadProc(LPVOID threadParam)
if (commandLine.m_executableType == CommandLine::ExecutableType::Path)
{
StringBuilder cmd;
- appendCommandLineEscaped(commandLine.m_executable.getUnownedSlice(), cmd);
+ StringEscapeUtil::appendMaybeQuoted(getEscapeHandler(), commandLine.m_executable.getUnownedSlice(), cmd);
pathBuffer = cmd.toWString();
path = pathBuffer.begin();