wildmatch: adjust "**" behavior
[gitweb.git] / wildmatch.c
index 5469866e8ad82eb3a1d32f60c9ef72251e07bde3..85bc0df8f814f18f9b10f9eccea0620ae8d9b9bc 100644 (file)
@@ -21,11 +21,6 @@ typedef unsigned char uchar;
 #define FALSE 0
 #define TRUE 1
 
-#define NOMATCH 1
-#define MATCH 0
-#define ABORT_ALL -1
-#define ABORT_TO_STARSTAR -2
-
 #define CC_EQ(class, len, litmatch) ((len) == sizeof (litmatch)-1 \
                                    && *(class) == *(litmatch) \
                                    && strncmp((char*)class, litmatch, len) == 0)
@@ -90,8 +85,14 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
                        continue;
                case '*':
                        if (*++p == '*') {
+                               const uchar *prev_p = p - 2;
                                while (*++p == '*') {}
-                               special = TRUE;
+                               if ((prev_p == text || *prev_p == '/') ||
+                                   (*p == '\0' || *p == '/' ||
+                                    (p[0] == '\\' && p[1] == '/'))) {
+                                       special = TRUE;
+                               } else
+                                       return ABORT_MALFORMED;
                        } else
                                special = FALSE;
                        if (*p == '\0') {