Add a maximum OSC 8 URI length of 2MB following iTerm2 (#14198)

c0b2f488c1

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

(cherry picked from commit 07201d6cd1)
Service-Card-Id: 86182617
Service-Version: 1.15
This commit is contained in:
Dustin L. Howett
2022-10-12 17:16:38 -05:00
committed by Dustin Howett
parent 24a8463818
commit 0f6d29adaf
3 changed files with 6 additions and 2 deletions

View File

@@ -659,7 +659,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->GetHyperlinkAtPosition(*_lastHoveredCell) };
auto uri{ _terminal->GetHyperlinkAtPosition(*_lastHoveredCell) };
uri.resize(std::min<size_t>(1024u, uri.size())); // Truncate for display
return winrt::hstring{ uri };
}
return {};
}

View File

@@ -973,7 +973,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)

View File

@@ -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<ITermDispatch> pDispatch);
bool ActionExecute(const wchar_t wch) override;