bug-bash
[Top][All Lists]
Advanced

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

xtrace ansi quoting vs shell metas


From: Grisha Levit
Subject: xtrace ansi quoting vs shell metas
Date: Sat, 24 Jun 2023 21:40:01 -0400

When printing the command for xtrace, if a word or assignment rhs contains
a shell meta character, ansi quoting is not applied even if it otherwise
should be.

$ (set -x; : $'_\1' $'*\1') |& cat -v
+ : $'_\001' '*^A'

It seems that the order of the sh_contains_shell_metas and
ansic_shouldquote tests should be reversed in the xtrace_print_* functions
(which would match their usage in the rest of the code)
---
diff --git a/print_cmd.c b/print_cmd.c
index f8524e04..d7c5bbf9 100644
--- a/print_cmd.c
+++ b/print_cmd.c
@@ -514,10 +514,10 @@ xtrace_print_assignment (char *name, char
*value, int assign_list, int xflags)
   /* VALUE should not be NULL when this is called. */
   if (*value == '\0' || assign_list)
     nval = value;
-  else if (sh_contains_shell_metas (value))
-    nval = sh_single_quote (value);
   else if (ansic_shouldquote (value))
     nval = ansic_quote (value, 0, (int *)0);
+  else if (sh_contains_shell_metas (value))
+    nval = sh_single_quote (value);
   else
     nval = value;

@@ -554,15 +554,15 @@ xtrace_print_word_list (WORD_LIST *list, int xtflags)
        fprintf (xtrace_fp, "''%s", w->next ? " " : "");
       else if (xtflags & 2)
        fprintf (xtrace_fp, "%s%s", t, w->next ? " " : "");
-      else if (sh_contains_shell_metas (t))
+      else if (ansic_shouldquote (t))
        {
-         x = sh_single_quote (t);
+         x = ansic_quote (t, 0, (int *)0);
          fprintf (xtrace_fp, "%s%s", x, w->next ? " " : "");
          free (x);
        }
-      else if (ansic_shouldquote (t))
+      else if (sh_contains_shell_metas (t))
        {
-         x = ansic_quote (t, 0, (int *)0);
+         x = sh_single_quote (t);
          fprintf (xtrace_fp, "%s%s", x, w->next ? " " : "");
          free (x);
        }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]