Skip to content

Commit

Permalink
Don't erase the prompt text when backspacing on a secret prompt with …
Browse files Browse the repository at this point in the history
…a null mask.
  • Loading branch information
danielcweber authored and patriksvensson committed Feb 13, 2024
1 parent 7270452 commit bf3b91a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ internal static async Task<string> ReadLine(this IAnsiConsole console, Style? st
if (text.Length > 0)
{
text = text.Substring(0, text.Length - 1);
console.Write("\b \b");

if (mask != null)
{
console.Write("\b \b");
}
}

continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Favorite fruit?
19 changes: 19 additions & 0 deletions test/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,25 @@ public Task Should_Choose_Masked_Default_Value_If_Nothing_Is_Entered_And_Prompt_
return Verifier.Verify(console.Output);
}

[Fact]
[Expectation("SecretValueBackspaceNullMask")]
public Task Should_Not_Erase_Prompt_Text_On_Backspace_If_Prompt_Is_Secret_And_Mask_Is_Null()
{
// Given
var console = new TestConsole();
console.Input.PushText("Bananas");
console.Input.PushKey(ConsoleKey.Backspace);
console.Input.PushKey(ConsoleKey.Enter);

// When
console.Prompt(
new TextPrompt<string>("Favorite fruit?")
.Secret(null));

// Then
return Verifier.Verify(console.Output);
}

[Fact]
[Expectation("SecretDefaultValueCustomMask")]
public Task Should_Choose_Custom_Masked_Default_Value_If_Nothing_Is_Entered_And_Prompt_Is_Secret_And_Mask_Is_Custom()
Expand Down

0 comments on commit bf3b91a

Please sign in to comment.