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 4386bf0 commit 9eabd09
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.
std::wstring_view fullPathView{ fullPath };
size_t pos;
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 9eabd09

Please sign in to comment.