From c67aeea761a74f119bd5a1a5008577aa1bde8c7c Mon Sep 17 00:00:00 2001 From: Maximus5 Date: Sun, 6 May 2018 01:18:53 +0300 Subject: [PATCH] Quotation fix for rprichard/wslbridge#22 If wslbridge and backend are installed in the folder containing spaces, bash exits immediately with error wslbridge error: failed to start backend process note: backend error output: /bin/bash: /mnt/c/Program: No such file or directory --- frontend/wslbridge.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/wslbridge.cc b/frontend/wslbridge.cc index 0378b02..6c13ff5 100644 --- a/frontend/wslbridge.cc +++ b/frontend/wslbridge.cc @@ -713,14 +713,15 @@ static void appendBashArg(std::wstring &out, const std::wstring &arg) { inQuote = newInQuote; } }; + enterQuote(true); for (auto ch : arg) { if (ch == L'\'') { enterQuote(false); out.append(L"\\'"); + enterQuote(true); } else if (isCharSafe(ch)) { out.push_back(ch); } else { - enterQuote(true); out.push_back(ch); } } @@ -1129,11 +1130,11 @@ int main(int argc, char *argv[]) { // Prepare the backend command line. std::wstring bashCmdLine; - bashCmdLine.append(L"$(if [ \"$(command -v wslpath)\" ]; then wslpath"); + bashCmdLine.append(L"\"$(if [ \"$(command -v wslpath)\" ]; then wslpath"); appendBashArg(bashCmdLine, backendPathWin); bashCmdLine.append(L" || echo false; else echo"); appendBashArg(bashCmdLine, backendPathWsl); - bashCmdLine.append(L"; fi)"); + bashCmdLine.append(L"; fi)\""); if (debugFork) { appendBashArg(bashCmdLine, L"--debug-fork");