jline / jline3

JLine is a Java library for handling console input.
Other
1.49k stars 218 forks source link

InputValue prompt with mask doesn't return the enter value, only the repeated mask character #1103

Open fkirchhoff opened 1 month ago

fkirchhoff commented 1 month ago

This example illustrates the problem:

        Terminal terminal = TerminalBuilder.builder().system(true).build();
        ConsolePrompt consolePrompt = new ConsolePrompt(terminal);
        PromptBuilder builder = consolePrompt.getPromptBuilder().createInputPrompt()
                .name("secret").message("secret>").mask('*').addPrompt();
        Map<String, PromptResultItemIF> answer = consolePrompt.prompt(builder.build());
        System.out.println("secret:"+answer.get("secret").getResult());

will result in:

? secret> ****
secret:****

even though I entered 1234.

ericparton commented 3 weeks ago

I'm also seeing the same issue

fkirchhoff commented 2 weeks ago

As I was trying to fix the issue locally (in the absence of https://github.com/jline/jline3/pull/1068), I noticed that ConsolePrompt copies the prompt value to be echoed back, which would result displaying the non-masked value.