jline / jline3

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

Buffer isn't cleared properly when quotes are involved #1036

Open HolyMolyCowMan opened 3 months ago

HolyMolyCowMan commented 3 months ago

It would seem that when the input to a completer includes a double quote character as the first character and there are multiple completion candidates, the parser doesn't correctly remove the quote before adding the beginning and end quote back in. This leads to 3 quote characters instead of 2.

This happens when using the default parser & highlighter and built in completers as shown in the below snippet. Entering "Ex and then pressing tab would lead to ""Example1" as the output.

reader = LineReaderBuilder.builder().parser(new DefaultParser())
                .completer(new StringsCompleter("Example1", "Example2")).highlighter(new DefaultHighlighter())
                .terminal(terminal).build();

        reader.setOpt(Option.MENU_COMPLETE); // Show completion options as menu
        reader.unsetOpt(Option.CASE_INSENSITIVE);

        // Create auto-suggestion widgets and enable it
        AutosuggestionWidgets autosuggestionWidgets = new AutosuggestionWidgets(reader);
        autosuggestionWidgets.enable();

I have also had this happen when there are quotes at the beginning and the end, leading to part of the string being included too. "Example" and then pressing tab would lead to "EExample1.

gnodet commented 1 month ago

Could you double check if that happens on other kind of terminals ?