From 07201d6cd12870755efa7bb52e220b0b10102730 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Wed, 12 Oct 2022 17:16:38 -0500 Subject: [PATCH] Add a maximum OSC 8 URI length of 2MB following iTerm2 (#14198) https://github.com/gnachman/iTerm2/commit/c0b2f488c1bde541676edd50ed9d3cb12a061275 Unlike iTerm2, we're not planning on making it configurable. This commit also adds a max length of 1024 characters on the "display URI" that we pass up to XAML, so as to not inundate the UI. Fixes #14200 --- src/cascadia/TerminalControl/ControlCore.cpp | 4 +++- src/terminal/parser/OutputStateMachineEngine.cpp | 2 +- src/terminal/parser/OutputStateMachineEngine.hpp | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 7fa53304299..cc9a1d1cb38 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -692,7 +692,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation auto lock = _terminal->LockForReading(); // Lock for the duration of our reads. if (_lastHoveredCell.has_value()) { - return winrt::hstring{ _terminal->GetHyperlinkAtViewportPosition(*_lastHoveredCell) }; + auto uri{ _terminal->GetHyperlinkAtViewportPosition(*_lastHoveredCell) }; + uri.resize(std::min(1024u, uri.size())); // Truncate for display + return winrt::hstring{ uri }; } return {}; } diff --git a/src/terminal/parser/OutputStateMachineEngine.cpp b/src/terminal/parser/OutputStateMachineEngine.cpp index 771d942a704..d6227383e53 100644 --- a/src/terminal/parser/OutputStateMachineEngine.cpp +++ b/src/terminal/parser/OutputStateMachineEngine.cpp @@ -989,7 +989,7 @@ bool OutputStateMachineEngine::_ParseHyperlink(const std::wstring_view string, const auto midPos = string.find(';'); if (midPos != std::wstring::npos) { - uri = string.substr(midPos + 1); + uri = string.substr(midPos + 1, MAX_URL_LENGTH); const auto paramStr = string.substr(0, midPos); const auto paramParts = Utils::SplitString(paramStr, ':'); for (const auto& part : paramParts) diff --git a/src/terminal/parser/OutputStateMachineEngine.hpp b/src/terminal/parser/OutputStateMachineEngine.hpp index 78c82abebbd..eb29ca9de5d 100644 --- a/src/terminal/parser/OutputStateMachineEngine.hpp +++ b/src/terminal/parser/OutputStateMachineEngine.hpp @@ -26,6 +26,8 @@ namespace Microsoft::Console::VirtualTerminal class OutputStateMachineEngine : public IStateMachineEngine { public: + static constexpr size_t MAX_URL_LENGTH = 2 * 1048576; // 2MB, like iTerm2 + OutputStateMachineEngine(std::unique_ptr pDispatch); bool ActionExecute(const wchar_t wch) override;