A `/' followed by `(' should not be considered an unquoted glob character:

$ bash -O failglob -c ': $1' _ 'a/(b)'
_: line 1: no match: a/(b)

If extglob is not turned on, it probably doesn't make sense to treat words
that don't have any non-extended glob characters as patterns:

$ bash -O failglob -c ': $1' _ '+(x)'
_: line 1: no match: +(x)

A CTLESC-escaped character should be treated as such even if it follows an
unquoted backslash, same as in quote_string_for_globbing:

$ bash -O failglob -c $': $1\1*' _ '\'
$ #not treated as glob, no error

Also simplfy the code a bit since the bstart code has been retired.
---
 pathexp.c | 38 ++++++++++++--------------------------
 1 file changed, 12 insertions(+), 26 deletions(-)

diff --git a/pathexp.c b/pathexp.c
index a849ec76..cfb8c9f3 100644
--- a/pathexp.c
+++ b/pathexp.c
@@ -67,11 +67,11 @@ unquoted_glob_pattern_p (char *string)
 {
   register int c;
   char *send;
-  int open, bsquote;
+  int open;

   DECLARE_MBSTATE;

-  open = bsquote = 0;
+  open = 0;
   send = string + strlen (string);

   while (c = *string++)
@@ -94,32 +94,23 @@ unquoted_glob_pattern_p (char *string)
  case '/':
    if (open)
      open = 0;
+   continue;

+#if defined (EXTENDED_GLOB)
  case '+':
  case '@':
  case '!':
-   if (*string == '(') /*)*/
+   if (extended_glob && *string == '(') /*)*/
      return (1);
    continue;
-
- /* A pattern can't end with a backslash, but a backslash in the pattern
-    can be special to the matching engine, so we note it in case we
-    need it later. */
+#endif
  case '\\':
-   if (*string != '\0' && *string != '/')
-     {
-       bsquote = 1;
-       string++;
-       continue;
-     }
-   else if (open && *string == '/')
-     {
-       string++; /* quoted slashes in bracket expressions are ok */
-       continue;
-     }
-   else if (*string == 0)
-     return (0);
-
+   /* 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. */
+   if (*string == CTLESC)
+     string++;
+   /* Fall through */
  case CTLESC:
    if (*string++ == '\0')
      return (0);
@@ -135,12 +126,7 @@ unquoted_glob_pattern_p (char *string)
       ADVANCE_CHAR_P (string, send - string);
 #endif
     }
-
-#if 0
-  return (bsquote ? 2 : 0);
-#else
   return (0);
-#endif
 }

 /* Return 1 if C is a character that is `special' in a POSIX ERE and needs to
-- 
2.42.0

Reply via email to