From 1429755c82b4168205940352e14cd00ef93337dd Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 3 Sep 2020 17:29:44 -0400 Subject: [PATCH 1/6] support the file URI scheme --- src/cascadia/TerminalApp/TerminalPage.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index ceb86a52481..860146d05e7 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1805,6 +1805,22 @@ namespace winrt::TerminalApp::implementation { ShellExecute(nullptr, L"open", eventArgs.Uri().c_str(), nullptr, nullptr, SW_SHOWNORMAL); } + if (parsed.SchemeName() == L"file") + { + const auto host = parsed.Host(); + // If no hostname was provided or if the hostname was "localhost", Host() will return null + // and we allow it + if (host == L"") + { + ShellExecute(nullptr, L"open", eventArgs.Uri().c_str(), nullptr, nullptr, SW_SHOWNORMAL); + } + // TODO: by the OSC 8 spec, if a hostname (other than localhost) is provided, we _should_ be + // comparing that value against what is returned by GetComputerNameExW and making sure they match. + // However, ShellExecute does not seem to be happy with file URIs of the form + // file://{hostname}/path/to/file.ext + // and so while we could do the hostname matching, we do not know how to actually open the URI + // if its given in that form. So for now we ignore all hostnames other than localhost + } } CATCH_LOG(); } From 7e66268557c7d55db0fb501168ee2ea3a8bf8c82 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 3 Sep 2020 17:44:20 -0400 Subject: [PATCH 2/6] dictionary --- .github/actions/spell-check/dictionary/dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/spell-check/dictionary/dictionary.txt b/.github/actions/spell-check/dictionary/dictionary.txt index 7344a626ea2..6f0d9c7047f 100644 --- a/.github/actions/spell-check/dictionary/dictionary.txt +++ b/.github/actions/spell-check/dictionary/dictionary.txt @@ -183437,6 +183437,7 @@ hostlership hostlerwife hostless hostly +hostname hostry hosts hostship From 2e7bc32d171bf35d78499017fe9424e345d363cd Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Fri, 4 Sep 2020 17:12:28 -0400 Subject: [PATCH 3/6] added helper function --- src/cascadia/TerminalApp/TerminalPage.cpp | 47 +++++++++++++++-------- src/cascadia/TerminalApp/TerminalPage.h | 2 + 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 860146d05e7..d7c4922d541 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1801,28 +1801,43 @@ namespace winrt::TerminalApp::implementation try { auto parsed = winrt::Windows::Foundation::Uri(eventArgs.Uri().c_str()); - if (parsed.SchemeName() == L"http" || parsed.SchemeName() == L"https") + if (_IsUriSupported(parsed)) { ShellExecute(nullptr, L"open", eventArgs.Uri().c_str(), nullptr, nullptr, SW_SHOWNORMAL); } - if (parsed.SchemeName() == L"file") + } + CATCH_LOG(); + } + + // Method Description: + // - Determines if the given URI is currently supported + // Arguments: + // - The parsed URI + // Return value: + // - True if we support it, false otherwise + bool TerminalPage::_IsUriSupported(winrt::Windows::Foundation::Uri parsedUri) + { + if (parsedUri.SchemeName() == L"http" || parsedUri.SchemeName() == L"https") + { + return true; + } + if (parsedUri.SchemeName() == L"file") + { + const auto host = parsedUri.Host(); + // If no hostname was provided or if the hostname was "localhost", Host() will return null + // and we allow it + if (host == L"") { - const auto host = parsed.Host(); - // If no hostname was provided or if the hostname was "localhost", Host() will return null - // and we allow it - if (host == L"") - { - ShellExecute(nullptr, L"open", eventArgs.Uri().c_str(), nullptr, nullptr, SW_SHOWNORMAL); - } - // TODO: by the OSC 8 spec, if a hostname (other than localhost) is provided, we _should_ be - // comparing that value against what is returned by GetComputerNameExW and making sure they match. - // However, ShellExecute does not seem to be happy with file URIs of the form - // file://{hostname}/path/to/file.ext - // and so while we could do the hostname matching, we do not know how to actually open the URI - // if its given in that form. So for now we ignore all hostnames other than localhost + return true; } + // TODO: by the OSC 8 spec, if a hostname (other than localhost) is provided, we _should_ be + // comparing that value against what is returned by GetComputerNameExW and making sure they match. + // However, ShellExecute does not seem to be happy with file URIs of the form + // file://{hostname}/path/to/file.ext + // and so while we could do the hostname matching, we do not know how to actually open the URI + // if its given in that form. So for now we ignore all hostnames other than localhost } - CATCH_LOG(); + return false; } // Method Description: diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index ac68997afae..dc5ce47630e 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -173,6 +173,8 @@ namespace winrt::TerminalApp::implementation const Microsoft::Terminal::TerminalControl::PasteFromClipboardEventArgs eventArgs); void _OpenHyperlinkHandler(const IInspectable sender, const Microsoft::Terminal::TerminalControl::OpenHyperlinkEventArgs eventArgs); + bool _IsUriSupported(const winrt::Windows::Foundation::Uri parsedUri); + bool _CopyText(const bool singleLine, const Windows::Foundation::IReference& formats); void _PasteText(); From 15dc61e73e4c14bfebc44b3587713b015724dd85 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Fri, 4 Sep 2020 17:38:41 -0400 Subject: [PATCH 4/6] nit --- src/cascadia/TerminalApp/TerminalPage.cpp | 2 +- src/cascadia/TerminalApp/TerminalPage.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index d7c4922d541..3ba60931704 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1815,7 +1815,7 @@ namespace winrt::TerminalApp::implementation // - The parsed URI // Return value: // - True if we support it, false otherwise - bool TerminalPage::_IsUriSupported(winrt::Windows::Foundation::Uri parsedUri) + bool TerminalPage::_IsUriSupported(const winrt::Windows::Foundation::Uri& parsedUri) { if (parsedUri.SchemeName() == L"http" || parsedUri.SchemeName() == L"https") { diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index dc5ce47630e..e5a813a6f15 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -173,7 +173,7 @@ namespace winrt::TerminalApp::implementation const Microsoft::Terminal::TerminalControl::PasteFromClipboardEventArgs eventArgs); void _OpenHyperlinkHandler(const IInspectable sender, const Microsoft::Terminal::TerminalControl::OpenHyperlinkEventArgs eventArgs); - bool _IsUriSupported(const winrt::Windows::Foundation::Uri parsedUri); + bool _IsUriSupported(const winrt::Windows::Foundation::Uri& parsedUri); bool _CopyText(const bool singleLine, const Windows::Foundation::IReference& formats); From 4ac7a85db8b03d234bb4b43ff6e1192256e191e7 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 8 Oct 2020 12:47:49 -0400 Subject: [PATCH 5/6] fix comment --- src/cascadia/TerminalApp/TerminalPage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index ff6bb31e2fa..fff505cba42 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1856,7 +1856,7 @@ namespace winrt::TerminalApp::implementation if (parsedUri.SchemeName() == L"file") { const auto host = parsedUri.Host(); - // If no hostname was provided or if the hostname was "localhost", Host() will return null + // If no hostname was provided or if the hostname was "localhost", Host() will return an empty string // and we allow it if (host == L"") { From c294dfeaf9015f38a1eb889e4cf7414a2f0e5e3d Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 18 Feb 2021 16:18:33 -0800 Subject: [PATCH 6/6] spell --- .github/actions/spelling/dictionary/dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/spelling/dictionary/dictionary.txt b/.github/actions/spelling/dictionary/dictionary.txt index 7b3ff5b78a2..2b3236d31dc 100644 --- a/.github/actions/spelling/dictionary/dictionary.txt +++ b/.github/actions/spelling/dictionary/dictionary.txt @@ -183444,6 +183444,7 @@ hostlerwife hostless hostly hostname +hostnames hostry hosts hostship