bug-bash
[Top][All Lists]
Advanced

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

Re: [PATCH] expanding $'\c^A'


From: Chet Ramey
Subject: Re: [PATCH] expanding $'\c^A'
Date: Fri, 13 Oct 2023 12:13:11 -0400
User-agent: Mozilla Thunderbird

On 10/13/23 12:36 AM, Grisha Levit wrote:
Handle $'\c^A' and $'\c^?' correctly when expanded by the parser:

$ bash -c $'printf "%q\n" $\'\\c\001 \\c\177\''
$'\001\001 \001\177'

---
diff --git a/lib/sh/strtrans.c b/lib/sh/strtrans.c
index d3b27f3b..3df33ade 100644
--- a/lib/sh/strtrans.c
+++ b/lib/sh/strtrans.c
@@ -198,6 +198,8 @@ ansicstr (const char *string, size_t len, int
flags, int *sawc, size_t *rlen)
     s++;
     if ((flags & 2) && c == '\\' && c == *s)
       s++; /* Posix requires $'\c\\' do backslash escaping */
+   else if ((flags & 2) && c == CTLESC && (*s == CTLESC || *s == CTLNUL))
+     s++;

It looks like that should be c = *s++. If there are literal ^A and ^? in
the input, the parser passes the string from parse_matched_pair as
'\c\001\001 \c\001\177' -- it adds the CTLESC escaping. I think your intent
here is to remove it.

Otherwise you change \c^? into ^A when it should end up being ^_.

--
``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]