Skip to content

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

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#2178
Moha-sami wants to merge 1 commit into
spectreconsole:mainfrom
Moha-sami:fix-textprompt-non-ascii-defaultvalue

Conversation

@Moha-sami

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.

@patriksvensson

Copy link
Copy Markdown
Contributor

@Moha-sami That issue you mention had been closed, and is not related to this change.

@patriksvensson

Copy link
Copy Markdown
Contributor

This PR needs a related issue.

Also, are you sure no AI has been used in this change? We need to know if so.

@Moha-sami

Copy link
Copy Markdown
Author

No But I'm new to This some how It's ok Will Just remove it my contribution was nothing anyway Good Luck

@Moha-sami Moha-sami closed this Jul 28, 2026
@Moha-sami
Moha-sami deleted the fix-textprompt-non-ascii-defaultvalue branch July 28, 2026 13:00
@patriksvensson

Copy link
Copy Markdown
Contributor

It's OK being new, but in the future, try following the contribution guidelines for projects that you want to contribute to.

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