-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Ensure PowerShell Core profile commandline is quoted #12086
Conversation
uuuuuuuuuugh thank you |
const auto& unquotedCommandline = psI.executablePath.native(); | ||
std::wstring quotedCommandline; | ||
quotedCommandline.reserve(unquotedCommandline.size() + 2); | ||
quotedCommandline.push_back(L'"'); | ||
quotedCommandline.append(unquotedCommandline); | ||
quotedCommandline.push_back(L'"'); | ||
profile->Commandline(winrt::hstring{ quotedCommandline }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for cheap tricks, we could also...
auto quotedCommandline = fmt::format(FMT_COMPILE(L"\"{}\""), psI.executablePath.native());
which should (?????) compile down to effectively optimal code (!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A micro-benchmark on my machine shows my code to be faster :)
auto start = std::chrono::steady_clock::now();
for (int i = 0; i < 1000000; i++)
{
const auto& unquotedCommandline = psI.executablePath.native();
std::wstring quotedCommandline;
quotedCommandline.reserve(unquotedCommandline.size() + 2);
quotedCommandline.push_back(L'"');
quotedCommandline.append(unquotedCommandline);
quotedCommandline.push_back(L'"');
profile->Commandline(winrt::hstring{ quotedCommandline });
}
auto end = std::chrono::steady_clock::now();
std::wstringstream stream;
stream << "Elapsed microseconds for native code " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << std::endl;
OutputDebugString(stream.str().c_str());
start = std::chrono::steady_clock::now();
for (int i = 0; i < 1000000; i++)
{
auto quotedCommandline = fmt::format(FMT_COMPILE(L"\"{}\""), psI.executablePath.native());
profile->Commandline(winrt::hstring{ quotedCommandline });
}
end = std::chrono::steady_clock::now();
std::wstringstream stream2;
stream2 << "Elapsed microseconds for fmt code " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << std::endl;
OutputDebugString(stream2.str().c_str());
Output:
Elapsed microseconds for native code 234055
Elapsed microseconds for fmt code 258514
Edit: Run the loop a factor of 10 more times, and do something with the constructed string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A micro-benchmark on my machine shows my code to be faster :)
Well, you'll make @lhecker 's day. And I chuckled. Good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL. Fair enough 😁
Hello @DHowett! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Ensures the PowerShell Core profile's commandline is quoted. This allows the profile to work correctly if there are files in place on the machine (e.g. one called `C:\Program`) that prevent `CreateProcess()` from invoking the un-quoted commandline. ## Validation Steps Performed Created a file called `C:\Program` and opened the PowerShell profile in terminal. Closes #11717 (cherry picked from commit 4930508)
🎉 Handy links: |
Ensures the PowerShell Core profile's commandline is quoted. This allows
the profile to work correctly if there are files in place on the machine
(e.g. one called
C:\Program
) that preventCreateProcess()
frominvoking the un-quoted commandline.
Validation Steps Performed
Created a file called
C:\Program
and opened the PowerShell profile interminal.
Closes #11717