Skip to content

fix(TextPrompt): prevent ArgumentOutOfRangeException for non-ASCII default values - #2177

Closed
Moha-sami wants to merge 1 commit into
spectreconsole:mainfrom
Moha-sami:fix-textprompt-non-ascii-defaultvalue
Closed

fix(TextPrompt): prevent ArgumentOutOfRangeException for non-ASCII default values#2177
Moha-sami wants to merge 1 commit into
spectreconsole:mainfrom
Moha-sami:fix-textprompt-non-ascii-defaultvalue

Conversation

@Moha-sami

@Moha-sami Moha-sami commented Jul 28, 2026

Copy link
Copy Markdown

Fixes #2152

  • I have read the Contribution Guidelines
  • I have checked that there isn't already another pull request that solves the above issue
  • All newly added code is adequately covered by tests
  • All existing tests are still running without errors

Changes

Problem

When using TextPrompt with EditableDefaultValue(true) containing non-ASCII or Unicode characters (e.g. "日本語" or "ä"), AnsiConsoleExtensions.Input.cs passed (ConsoleKey)ch to ConsoleKeyInfo, which throws ArgumentOutOfRangeException in .NET when ConsoleKey > 255.

Solution

  1. Updated AnsiConsoleExtensions.Input.cs to check (int)ch <= 255 ? (ConsoleKey)ch : (ConsoleKey)0, preventing out-of-range exceptions while maintaining full Unicode string processing.
  2. Added unit test Should_Not_Throw_When_Editable_Default_Value_Contains_Non_Ascii_Characters in TextPromptTests.cs.

@Moha-sami

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@patriksvensson

Copy link
Copy Markdown
Contributor

Thanks for opening this pull request. Before I can review it, the pull request template needs to be fully filled out so I have all the necessary context.

I’m going to close this for now, but feel free to update the template and reopen the PR once everything is completed as expected. Thanks!

@Moha-sami
Moha-sami deleted the fix-textprompt-non-ascii-defaultvalue branch July 28, 2026 13:00
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.

Status text wraps with incorrect alignment when text exceeds console width

2 participants