NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/54067: libed



>Number:         54067
>Category:       lib
>Synopsis:       libed
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 20 05:05:00 +0000 2019
>Originator:     Alexander Pyhalov
>Release:        
>Organization:
Southern Federal University
>Environment:
>Description:
https://github.com/NetBSD/src/commit/47081400d868e1d6dd5629bea97c599c48404839 has broken libedit compatibility to libreadline, which causes issues like incorrect completion in psql, when "space separated keywords" auto-complete as "space\ separated\ keywords". 
>How-To-Repeat:
The following program, linked with readline, autocomplete words as "Arthur Dent", "Ford Perfect" and so on. When linked with libedit, it autocomplete words as "Arthur\ Dent", "Ford\ Perfect" and so on.
(Note, this is checked with latest version of http://www.thrysoee.dk/editline/ on OpenIndiana, but issue is the same - rl_complete completes keywords as file names, which is incorrect.

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <readline/readline.h>
#include <readline/history.h>

char **character_name_completion(const char *, int, int);
char *character_name_generator(const char *, int);

char *character_names[] = {
    "Arthur Dent",
    "Ford Prefect",
    "Tricia McMillan",
    "Zaphod Beeblebrox",
    NULL
};

int main()
{
    rl_attempted_completion_function = character_name_completion;

    printf("Who's your favourite Hitchiker's Guide character?\n");
    char *buffer = readline("> ");
    if (buffer) {
        printf("You entered: %s\n", buffer);
        free(buffer);
    }

    return 0;
}

char **
character_name_completion(const char *text, int start, int end)
{
    rl_attempted_completion_over = 1;
    return rl_completion_matches(text, character_name_generator);
}

char *
character_name_generator(const char *text, int state)
{
    static int list_index, len;
    char *name;

    if (!state) {
        list_index = 0;
        len = strlen(text);
    }

    while ((name = character_names[list_index++])) {
        if (strncmp(name, text, len) == 0) {
            return strdup(name);
        }
    }

    return NULL;
}

>Fix:
So far, we are likely to revert this commit using the following patch:

--- libedit-20181209-3.1/src/filecomplete.c.~1~ 2018-05-25 21:09:38.000000000 +0000
+++ libedit-20181209-3.1/src/filecomplete.c     2019-03-20 07:48:13.111605101 +0000
@@ -650,15 +650,11 @@
                                 * it, unless we do filename completion and the
                                 * object is a directory. Also do necessary escape quoting
                                 */
-                               char *escaped_completion = escape_filename(el, matches[0]);
-                               if (escaped_completion == NULL)
-                                       goto out;
                                el_winsertstr(el,
-                                       ct_decode_string(escaped_completion, &el->el_scratch));
+                                       ct_decode_string(matches[0], &el->el_scratch));
                                el_winsertstr(el,
-                                               ct_decode_string((*app_func)(escaped_completion),
+                                               ct_decode_string((*app_func)(matches[0]),
                                                        &el->el_scratch));
-                               free(escaped_completion);
                        } else {
                                /*
                                 * Only replace the completed string with common part of



Home | Main Index | Thread Index | Old Index