]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - lib/glob/glob_loop.c
Bash-5.0 patch 3: improvements when globbing directory names containing backslashes
[thirdparty/bash.git] / lib / glob / glob_loop.c
index 7d6ae2113c509ec64a9087b03ce4c04e67b217b9..3a4f4f1e86efec638c07d4f2471b9bf514897123 100644 (file)
@@ -26,10 +26,10 @@ INTERNAL_GLOB_PATTERN_P (pattern)
 {
   register const GCHAR *p;
   register GCHAR c;
-  int bopen;
+  int bopen, bsquote;
 
   p = pattern;
-  bopen = 0;
+  bopen = bsquote = 0;
 
   while ((c = *p++) != L('\0'))
     switch (c)
@@ -55,13 +55,22 @@ INTERNAL_GLOB_PATTERN_P (pattern)
 
       case L('\\'):
        /* Don't let the pattern end in a backslash (GMATCH returns no match
-          if the pattern ends in a backslash anyway), but otherwise return 1,
-          since the matching engine uses backslash as an escape character
-          and it can be removed. */
-       return (*p != L('\0'));
+          if the pattern ends in a backslash anyway), but otherwise note that 
+          we have seen this, since the matching engine uses backslash as an
+          escape character and it can be removed. We return 2 later if we
+          have seen only backslash-escaped characters, so interested callers
+          know they can shortcut and just dequote the pathname. */
+       if (*p != L('\0'))
+         {
+           p++;
+           bsquote = 1;
+           continue;
+         }
+       else    /* (*p == L('\0')) */
+         return 0;
       }
 
-  return 0;
+  return bsquote ? 2 : 0;
 }
 
 #undef INTERNAL_GLOB_PATTERN_P