]> xenbits.xensource.com Git - libvirt.git/commit
vshReadlineParse: Escape list of candidates earlier
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 26 Jan 2021 08:23:24 +0000 (09:23 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 26 Jan 2021 15:46:41 +0000 (16:46 +0100)
commitf61a4e91ef45f4f7a3f5a6e02896823128927e6c
tree24be0152ff0969410aa7fe51e94c2be4908bbeac
parentc31e80c653978eff9747a6df99853cb14817ba5a
vshReadlineParse: Escape list of candidates earlier

The way our completer callbacks work is that they return all
possible candidates and then vshCompleterFilter() is called to
prune the list of all candidates removing those which don't match
user's input. This allows us to have simpler completer callbacks
as their only job is to fetch all possible candidates.

Anyway, if the completion candidate we're returning contains a
space, it has to be escaped (shell like escaping), unless there
is already a quote character (single quote or double quote).

But ordering is critical. Completer callback returns string
without any escaping, but the filter function sees the user input
escaped. For instance, if user's input is "domain with
space<TAB>" then the filtering function gets "domain\ with\
space" as user's input but completer returns "domain with space".
Since these two strings don't match the filtering function
removes this candidate from the list. What we need to do is to
escape strings before calling the filtering function. This way,
the filtering function will see two same strings.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/vsh.c