Skip to content

Commit 59aaba7

Browse files
authored
Fix a crash in the GenerateName for SearchForTextArgs (#16054)
Fixes MSFT:46725264 don't explode trying to parse a URL, if the string wasn't one.
1 parent 8521aae commit 59aaba7

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/cascadia/TerminalSettingsModel/ActionArgs.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,25 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
814814

815815
winrt::hstring SearchForTextArgs::GenerateName() const
816816
{
817-
return winrt::hstring{
818-
fmt::format(std::wstring_view(RS_(L"SearchForTextCommandKey")),
819-
Windows::Foundation::Uri(QueryUrl()).Domain().c_str())
820-
};
817+
if (QueryUrl().empty())
818+
{
819+
// Return the default command name, because we'll just use the
820+
// default search engine for this.
821+
return RS_(L"SearchWebCommandKey");
822+
}
823+
824+
try
825+
{
826+
return winrt::hstring{
827+
fmt::format(std::wstring_view(RS_(L"SearchForTextCommandKey")),
828+
Windows::Foundation::Uri(QueryUrl()).Domain().c_str())
829+
};
830+
}
831+
CATCH_LOG();
832+
833+
// We couldn't parse a URL out of this. Return no string at all, so that
834+
// we don't even put this into the command palette.
835+
return L"";
821836
}
822837

823838
winrt::hstring GlobalSummonArgs::GenerateName() const

0 commit comments

Comments
 (0)