Skip to content

Commit

Permalink
Escape single quotes for WSL
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
a4lg committed Oct 8, 2024
1 parent aa256ad commit bcf2c74
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3287,7 +3287,26 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
allPathsString.push_back(quotesChar);
}
allPathsString.append(fullPath);
if (isWSL)
{
// Fix quoted path for WSL
// Single quote is allowed on the Win32 subsystem and must be processed
// when we are quoting the path with single quotes (on WSL).
// Note that we assume that all paths are quoted for WSL.
size_t pos;
auto fullPathView = std::wstring_view(fullPath);
while ((pos = fullPathView.find(L"'")) != std::wstring_view::npos)
{
allPathsString.append(fullPathView.begin(), fullPathView.begin() + pos);
allPathsString.append(L"'\"'\"'");
fullPathView.remove_prefix(pos + 1);
}
allPathsString.append(fullPathView);
}
else
{
allPathsString.append(fullPath);
}
if (quotesNeeded)
{
allPathsString.push_back(quotesChar);
Expand Down

0 comments on commit bcf2c74

Please sign in to comment.