bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] exclude: handle wildcards with FNM_NOESCAPE and with trailing \


From: Paul Eggert
Subject: [PATCH] exclude: handle wildcards with FNM_NOESCAPE and with trailing \
Date: Sun, 29 Apr 2012 17:04:13 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120411 Thunderbird/11.0.1

Another I-hope-obvious patch.

---
 ChangeLog     |    6 ++++++
 lib/exclude.c |   17 +++--------------
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index baff376..ae5ca9e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2012-04-29  Paul Eggert  <address@hidden>
+ exclude: handle wildcards with FNM_NOESCAPE and with trailing \
+       * lib/exclude.c (unescape_pattern): Don't worry about unescaped [;
+       it's not possible here.  Handle the case of \ at end of pattern
+       without dumping core.
+       (add_exclude): Do not unescape the pattern if FNM_NOESCAPE is used.
+
        _Noreturn: future-proof non-GNU and non-MSVC compilers
        * build-aux/snippet/_Noreturn.h (_Noreturn):
        * m4/gnulib-common.m4 (gl_COMMON_BODY):
diff --git a/lib/exclude.c b/lib/exclude.c
index d135b09..5aa6a7f 100644
--- a/lib/exclude.c
+++ b/lib/exclude.c
@@ -140,20 +140,9 @@ fnmatch_pattern_has_wildcards (const char *str, int 
options)
 static void
 unescape_pattern (char *str)
 {
-  int inset = 0;
-  char *q = str;
+  char const *q = str;
   do
-    {
-      if (inset)
-        {
-          if (*q == ']')
-            inset = 0;
-        }
-      else if (*q == '[')
-        inset = 1;
-      else if (*q == '\\')
-        q++;
-    }
+    q += *q == '\\' && q[1];
   while ((*str++ = *q++));
 }
@@ -503,7 +492,7 @@ add_exclude (struct exclude *ex, char const *pattern, int options)
         seg = new_exclude_segment (ex, exclude_hash, options);
str = xstrdup (pattern);
-      if (options & EXCLUDE_WILDCARDS)
+      if ((options & (EXCLUDE_WILDCARDS | FNM_NOESCAPE)) == EXCLUDE_WILDCARDS)
         unescape_pattern (str);
       p = hash_insert (seg->v.table, str);
       if (p != str)



reply via email to

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