Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape single quotes while translating dropped Win32 paths #18007

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
/* Cygwin */ L"/cygdrive/",
/* MSYS2 */ L"/",
};
static constexpr wil::zwstring_view sSingleQuoteEscape = L"'\\''";
static constexpr auto cchSingleQuoteEscape = sSingleQuoteEscape.size();

if (translationStyle == PathTranslationStyle::None)
{
Expand All @@ -75,6 +77,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// All of the other path translation modes current result in /-delimited paths
std::replace(fullPath.begin(), fullPath.end(), L'\\', L'/');

// Escape single quotes, assuming translated paths are always quoted by a pair of single quotes.
size_t pos = 0;
while ((pos = fullPath.find(L'\'', pos)) != std::wstring::npos)
{
// ' -> '\'' (for POSIX shell)
fullPath.replace(pos, 1, sSingleQuoteEscape);
// Arithmetic overflow cannot occur here.
pos += cchSingleQuoteEscape;
}

if (fullPath.size() >= 2 && fullPath.at(1) == L':')
{
// C:/foo/bar -> Cc/foo/bar
Expand Down
Loading