Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextPrompt.cs "Invalid Input" validation error for empty Nullable<T> #998

Closed
iraklikhitarishvili opened this issue Oct 6, 2022 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@iraklikhitarishvili
Copy link

iraklikhitarishvili commented Oct 6, 2022

Information

  • OS: Windows/WSL2
  • Version: 20.04.4 LTS
  • Terminal: Windows Terminal

Describe the bug
"Invalid Input" validation error is returned if:

  1. prompt is TextPrompt<Nullable<T>>
  2. AllowEmpty() is specified
  3. input is empty

To Reproduce
Code snippet for prompt:

var result = AnsiConsole.Prompt(new TextPrompt<int?>("Some message").AllowEmpty());
AnsiConsole.MarkupLine($"Result is {result.Value}");

Output:
invalid_input

Expected behavior
Since :

  • AllowEmpty is true
  • TypeConvertor for Nullable<T> returns true

Validation error should not occur. Instead null should be returned.

Additional context
In implementation:

  • Empty input is checked here and then
  • AllowEmpty flag is checked here

Only after this following snippet is executed

else if (!TypeConverterHelper.TryConvertFromString<T>(input, out result) || result == null)
{
    console.MarkupLine(ValidationErrorMessage);
    WritePrompt(console);
    continue;
}

Will it be wrong to remove || result == null?
AllowEmpty is already checked and it's allowed.
TypeConverterHelper.TryConvertFromString<T>(input, out result) says that conversion is successful.

@nils-a
Copy link
Contributor

nils-a commented Nov 22, 2022

Closing as duplicate of #714

@nils-a nils-a closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2022
Repository owner moved this from Todo 🕑 to Done 🚀 in Spectre Console Nov 22, 2022
@nils-a nils-a added duplicate This issue or pull request already exists and removed bug Something isn't working needs triage labels Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
Status: Done 🚀
Development

No branches or pull requests

2 participants