bug-bash
[Top][All Lists]
Advanced

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

Re: [PATCH v2] read: non-raw-mode fixes


From: Chet Ramey
Subject: Re: [PATCH v2] read: non-raw-mode fixes
Date: Tue, 1 Aug 2023 18:37:44 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0

On 7/26/23 7:53 PM, Grisha Levit wrote:
On Wed, Jul 26, 2023 at 2:23 PM Grisha Levit <grishalevit@gmail.com> wrote:
If the last character read was an (unescaped) backslash, store it as
such instead of as a CTLESC.  Avoids:

$ printf '\\' | { read; echo "${REPLY@Q}"; }
bash: DEBUG warning: dequote_string: string with bare CTLESC
$'\001'

Sorry that was wrong, the CTLESC should just be removed.  Much simpler
patch below.

Thanks for the report and patch. I simplified it a little more by making
saw_escape into a real counter, and it will be in the next devel branch push.

Chet

---
diff --git a/builtins/read.def b/builtins/read.def
index 5b2621fe..ce5bcc38 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -751,11 +751,11 @@ read_builtin (WORD_LIST *list)
        if (pass_next)
         {
           pass_next = 0;
-         if (c == '\n')
+         if (c == '\n' || c == '\0')
             {
               if (skip_ctlesc == 0 && i > 0)
                 i--;            /* back up over the CTLESC */
-             if (interactive && input_is_tty && raw == 0)
+             if (interactive && input_is_tty && raw == 0 && c == '\n')
                 print_ps2 = 1;
             }
           else
@@ -825,6 +825,11 @@ add_char:
        if (nchars > 0 && nr >= nchars)
         break;
      }
+
+  if (pass_next && skip_ctlesc == 0)
+    i--;               /* back up over the CTLESC */
+  if (skip_ctlnul && saw_escape && i == 1 && input_string[0] == CTLNUL)
+    saw_escape = 0;    /* Avoid dequoting bare CTLNUL */
    input_string[i] = '\0';
    check_read_timeout ();


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

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