Skip to content

Commit

Permalink
Add a maximum OSC 8 URI length of 2MB following iTerm2 (#14198)
Browse files Browse the repository at this point in the history
gnachman/iTerm2@c0b2f48

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
  • Loading branch information
DHowett authored Oct 12, 2022
1 parent eebea51 commit 07201d6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(1024u, uri.size())); // Truncate for display
return winrt::hstring{ uri };
}
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/parser/OutputStateMachineEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/terminal/parser/OutputStateMachineEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 07201d6

Please sign in to comment.