On Sat, Oct 7, 2023 at 9:57 AM Chet Ramey <chet.ra...@case.edu> wrote:
>
> On 9/26/23 2:25 AM, Grisha Levit wrote:
> > A CTLESC-escaped character should be treated as such even if it follows an
> > unquoted backslash, same as in quote_string_for_globbing:
>
> Thanks for the report and patch.

Sorry I guess this part was incomplete, based on your earlier comment in [1].

If we want to preserve the behavior of unquoted backslash causing a following
quoted character to become unquoted after quote_string_for_globbing:

$ B=\\ bash-5.2 -O failglob -c ': $B"*"'
bash-5.2: line 1: no match: \*

then unquoted_glob_pattern_p needs to recognize that circumstance.

[1]: https://lists.gnu.org/archive/html/bug-bash/2023-10/msg00019.html

---
diff --git a/pathexp.c b/pathexp.c
index a050ca2c..873edc2c 100644
--- a/pathexp.c
+++ b/pathexp.c
@@ -104,11 +104,17 @@ unquoted_glob_pattern_p (char *string)
          continue;

        case '\\':
-         /* Even after an unquoted backslash, CTLESC either quotes the next
-            char or escapes a CTLESC or CTLNUL.  Either way, the character
-            after it is not an unquoted globbing char. */
+         /* A quoted character following an unquoted backslash will become
+            unquoted when passed through quote_string_for_globbing */
          if (*string == CTLESC)
-           string++;
+           {
+             string++;
+             /* If the CTLESC was quoting a CTLESC, skip it so that it's not
+                treated as a quoting character */
+             if (*string == CTLESC)
+               string++;
+           }
+         else
          /*FALLTHROUGH*/
        case CTLESC:
          if (*string++ == '\0')
-- 
2.42.0

Reply via email to