Skip to content

Case insensitive user text input comparison#1960

Closed
akinsmosu wants to merge 8 commits intospectreconsole:mainfrom
akinsmosu:case-insensitive-user-input-comparison
Closed

Case insensitive user text input comparison#1960
akinsmosu wants to merge 8 commits intospectreconsole:mainfrom
akinsmosu:case-insensitive-user-input-comparison

Conversation

@akinsmosu
Copy link
Copy Markdown

fixes #1906

  • I have read the Contribution Guidelines
  • I have commented on the issue above and discussed the intended changes
  • A maintainer has signed off on the changes and the issue was assigned to me
  • All newly added code is adequately covered by tests
  • All existing tests are still running without errors
  • The documentation was modified to reflect the changes OR no documentation changes are required.

Changes

Summary
This PR makes TextPrompt<string> case-insensitive when matching user input against defined choices. Previously, inputs such as "yes" would fail to match "Yes".

What this change does
When the TextPrompt's generic is a string and the user did not explicitly provide a comparer, it automatically configures _comparer to StringComparer.OrdinalIgnoreCase.

Adds a theory-based test to verify case-insensitive matching.

All existing behavior remains unchanged for non-string TextPrompt<T> usage.

Implementation Notes
Added a typeof(T) == typeof(string) check in TextPrompt<T> to detect string-based prompts. _comparer is set to StringComparison.OrdinalIgnoreCase only if the user does not supply a comparer.

@akinsmosu
Copy link
Copy Markdown
Author

@akinsmosu please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

@patriksvensson patriksvensson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great first PR, but there are some changes I would like to see before I merge this 👍

Comment thread src/Spectre.Console/Prompts/TextPrompt.cs Outdated
Comment thread src/Tests/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs
Comment thread src/Tests/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs
Comment thread src/Tests/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs Outdated
akinsmosu and others added 4 commits November 14, 2025 09:41
Co-authored-by: Patrik Svensson <patriksvensson@users.noreply.github.com>
Co-authored-by: Patrik Svensson <patriksvensson@users.noreply.github.com>
Co-authored-by: Patrik Svensson <patriksvensson@users.noreply.github.com>
Co-authored-by: Patrik Svensson <patriksvensson@users.noreply.github.com>
@akinsmosu
Copy link
Copy Markdown
Author

Thanks for the feedback! All suggestions applied.

@patriksvensson
Copy link
Copy Markdown
Contributor

Hi!

Thanks so much for taking the time to submit this PR.
I really appreciate the contribution!

Unfortunately, I haven’t had the capacity to review this in a timely manner, and since it was opened, the repository has changed significantly. Because of that, this PR is no longer in a state where it can be reviewed or merged as-is. This is not your fault, but mine, and I'm sorry about this.

I’m going to close it for now to help keep things tidy. That said, if you’re still interested in contributing, please feel free to open a new pull request that’s up to date with the current state of the repository, and I’ll be happy to take a look when I can. I'll promise I'll do better this time around.

Thanks again for your work and for your interest in the project!

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.

Ignore the case of the input for TextPrompt (select from multiple choices)

2 participants