mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-19 18:11:39 -05:00
more mangling
This commit is contained in:
@@ -450,4 +450,17 @@ void UtilsTests::TestMangleWSLPaths()
|
|||||||
VERIFY_ARE_EQUAL(LR"(wsl ~ -d Ubuntu)", commandline);
|
VERIFY_ARE_EQUAL(LR"(wsl ~ -d Ubuntu)", commandline);
|
||||||
VERIFY_ARE_EQUAL(startingDirectory, path);
|
VERIFY_ARE_EQUAL(startingDirectory, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Test for GH#11994 - make sure `//wsl$/` paths get mangled back to
|
||||||
|
// `\\wsl$\`, to workaround a potential bug in `wsl --cd`
|
||||||
|
auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl -d Ubuntu)", LR"(//wsl$/Ubuntu/home/user)");
|
||||||
|
VERIFY_ARE_EQUAL(LR"("wsl" --cd "\\wsl$\Ubuntu\home\user" -d Ubuntu)", commandline);
|
||||||
|
VERIFY_ARE_EQUAL(L"", path);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl -d Ubuntu)", LR"(\\wsl$\Ubuntu\home\user)");
|
||||||
|
VERIFY_ARE_EQUAL(LR"("wsl" --cd "\\wsl$\Ubuntu\home\user" -d Ubuntu)", commandline);
|
||||||
|
VERIFY_ARE_EQUAL(L"", path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -647,8 +647,23 @@ std::tuple<std::wstring, std::wstring> Utils::MangleStartingDirectoryForWSL(std:
|
|||||||
// Tilde followed by non-space should be okay (like, wsl -d Debian ~/blah.sh)
|
// Tilde followed by non-space should be okay (like, wsl -d Debian ~/blah.sh)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GH#11994 - If the path starts with //wsl$, then the user is
|
||||||
|
// likely passing a Windows-style path to the WSL filesystem,
|
||||||
|
// but with forward slashes instead of backslashes.
|
||||||
|
// Unfortunately, `wsl --cd` will try to treat this as a
|
||||||
|
// linux-relative path, which will fail to do the expected
|
||||||
|
// thing.
|
||||||
|
//
|
||||||
|
// In that case, manually mangle the startingDirectory to use
|
||||||
|
// backslashes as the path separator instead.
|
||||||
|
std::wstring mangledDirectory{ startingDirectory };
|
||||||
|
if (til::starts_with(mangledDirectory, L"//wsl$"))
|
||||||
|
{
|
||||||
|
mangledDirectory = std::filesystem::path{ startingDirectory }.make_preferred().wstring();
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fmt::format(LR"("{}" --cd "{}" {})", executablePath.wstring(), startingDirectory, arguments),
|
fmt::format(LR"("{}" --cd "{}" {})", executablePath.wstring(), mangledDirectory, arguments),
|
||||||
std::wstring{}
|
std::wstring{}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user