[PATCH 2/9] vsh: Don't break word on backslash

Michal Privoznik posted 9 patches 5 years ago
[PATCH 2/9] vsh: Don't break word on backslash
Posted by Michal Privoznik 5 years ago
A backslash is the way we escape characters in virsh. For
instance:

  virsh # start domain\ with\ long\ name

For readline completion, we do not want to get four separate
words ("domain", "with", "long", "name").  This means, that we
can't sue virBufferEscapeShell() because it doesn't escape spaces
the way we want.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tools/vsh.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 54253afa72..9856088126 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2773,7 +2773,7 @@ vshReadlineParse(const char *text, int state)
     if (ret &&
         !rl_completion_quote_character) {
         g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-        virBufferEscapeShell(&buf, ret);
+        virBufferEscape(&buf, '\\', " ", "%s", ret);
         VIR_FREE(ret);
         ret = virBufferContentAndReset(&buf);
     }
@@ -2819,7 +2819,7 @@ vshReadlineInit(vshControl *ctl)
     int ret = -1;
     char *histsize_env = NULL;
     const char *histsize_str = NULL;
-    const char *break_characters = " \t\n\\`@$><=;|&{(";
+    const char *break_characters = " \t\n`@$><=;|&{(";
     const char *quote_characters = "\"'";
 
     /* Opaque data for autocomplete callbacks. */
-- 
2.26.2

Re: [PATCH 2/9] vsh: Don't break word on backslash
Posted by Ján Tomko 5 years ago
On a Tuesday in 2021, Michal Privoznik wrote:
>A backslash is the way we escape characters in virsh. For
>instance:
>
>  virsh # start domain\ with\ long\ name
>
>For readline completion, we do not want to get four separate
>words ("domain", "with", "long", "name").  This means, that we
>can't sue virBufferEscapeShell() because it doesn't escape spaces

Let's leave the lawyers out of this.

Jano

>the way we want.
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> tools/vsh.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/tools/vsh.c b/tools/vsh.c
>index 54253afa72..9856088126 100644
>--- a/tools/vsh.c
>+++ b/tools/vsh.c
>@@ -2773,7 +2773,7 @@ vshReadlineParse(const char *text, int state)
>     if (ret &&
>         !rl_completion_quote_character) {
>         g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
>-        virBufferEscapeShell(&buf, ret);
>+        virBufferEscape(&buf, '\\', " ", "%s", ret);
>         VIR_FREE(ret);
>         ret = virBufferContentAndReset(&buf);
>     }
>@@ -2819,7 +2819,7 @@ vshReadlineInit(vshControl *ctl)
>     int ret = -1;
>     char *histsize_env = NULL;
>     const char *histsize_str = NULL;
>-    const char *break_characters = " \t\n\\`@$><=;|&{(";
>+    const char *break_characters = " \t\n`@$><=;|&{(";
>     const char *quote_characters = "\"'";
>
>     /* Opaque data for autocomplete callbacks. */