Skip to content

Commit 9eabd09

Browse files
committed
Escape single quotes for WSL
This commit escapes single quotes (allowed in the Win32 subsystem) with `'\''` (finish quote, print a single quote then begin quote again), which is a valid escape in the context of the POSIX shell, when a file/ folder is dropped to a WSL tab.
1 parent 4386bf0 commit 9eabd09

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/cascadia/TerminalControl/TermControl.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -3287,7 +3287,26 @@ namespace winrt::Microsoft::Terminal::Control::implementation
32873287
{
32883288
allPathsString.push_back(quotesChar);
32893289
}
3290-
allPathsString.append(fullPath);
3290+
if (isWSL)
3291+
{
3292+
// Fix quoted path for WSL
3293+
// Single quote is allowed on the Win32 subsystem and must be processed
3294+
// when we are quoting the path with single quotes (on WSL).
3295+
// Note that we assume that all paths are quoted for WSL.
3296+
std::wstring_view fullPathView{ fullPath };
3297+
size_t pos;
3298+
while ((pos = fullPathView.find(L'\'')) != std::wstring_view::npos)
3299+
{
3300+
allPathsString.append(fullPathView.begin(), fullPathView.begin() + pos);
3301+
allPathsString.append(L"'\\''");
3302+
fullPathView.remove_prefix(pos + 1);
3303+
}
3304+
allPathsString.append(fullPathView);
3305+
}
3306+
else
3307+
{
3308+
allPathsString.append(fullPath);
3309+
}
32913310
if (quotesNeeded)
32923311
{
32933312
allPathsString.push_back(quotesChar);

0 commit comments

Comments
 (0)