Skip to content

Escape text in AnsiMarkupSegment.ToString()#2055

Merged
patriksvensson merged 1 commit intospectreconsole:mainfrom
mitchdenny:fix/search-highlight-escaped-brackets
Mar 17, 2026
Merged

Escape text in AnsiMarkupSegment.ToString()#2055
patriksvensson merged 1 commit intospectreconsole:mainfrom
mitchdenny:fix/search-highlight-escaped-brackets

Conversation

@mitchdenny
Copy link
Contributor

Summary

AnsiMarkupSegment stores parsed (unescaped) text in its Text property, but ToString() inserted it directly into markup output without re-escaping square brackets. This caused SelectionPrompt with EnableSearch() to crash when any choice contained brackets (e.g. [Prod]), because the search highlighting split escaped bracket sequences into invalid markup.

Fix

Escape the Text property in ToString() before inserting it into markup output, for both styled and plain segments.

Tests

  • 6 new tests in AnsiMarkupTests.cs covering escaped brackets in Highlight()
  • 2 new tests in SelectionPromptTests.cs for search with bracketed choices

Fixes #2054

AnsiMarkupSegment stores parsed (unescaped) text, but ToString()
inserted it directly into markup output without re-escaping square
brackets. This caused SelectionPrompt with EnableSearch() to crash
when any choice contained brackets (e.g. [Prod]), because the search
highlighting split escaped bracket sequences into invalid markup.

Fixes spectreconsole#2054

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@patriksvensson patriksvensson merged commit 94a9a0b into spectreconsole:main Mar 17, 2026
3 checks passed
@patriksvensson
Copy link
Contributor

Merged! Thank you for your contribution. Much appreciated! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SelectionPrompt with EnableSearch() crashes when choices contain escaped square brackets

2 participants