From 972bd3c4c24b06501c52127416afb763a066b8ad Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 29 Apr 2021 09:01:46 -0400 Subject: Support for escaped paths in tools (#1823) * #include an absolute path didn't work - because paths were taken to always be relative. * Split out StringEscapeUtil. * Added StringEscapeUtil. * Fix typo in unix quoting type. * Small comment improvements. * Try to fix linux linking issue. * Fix typo. * Attempt to fix linux link issue. * Update VS proj even though nothing really changed. * Fix another typo issue. * Fix for windows issue. Fixed bug. * Make separate Utils for escaping. * Fix typo. * Split out into StringEscapeHandler. * Windows shell does handle removing quotes (so remove code to remove them). * Handle unescaping if not initiating using the shell. * Slight improvement around shell like decoding. * Simplify command extraction. * Add shared-library category type. * Fix bug in command extraction. * Typo in transcendental category. * Enable unit-test on in smoke test category. * Make parsing failing output as a failing test. * Fixes for transcendental tests. Disable tests that do not work. * Changed category parsing. * Removed the TestResult parameter from _gatherTestsForFile. Made testsList only output. * Remove testing if all tests were disabled. * Fix typo. * Disable path canonical test on linux because CI issue. --- source/core/windows/slang-win-process-util.cpp | 50 ++++++-------------------- 1 file changed, 11 insertions(+), 39 deletions(-) (limited to 'source/core/windows/slang-win-process-util.cpp') 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(); -- cgit v1.2.3