2 #include "git-compat-util.h"
10 static struct reg_flag reg_flags[] = {
11 { "EXTENDED", REG_EXTENDED },
12 { "NEWLINE", REG_NEWLINE },
13 { "ICASE", REG_ICASE },
14 { "NOTBOL", REG_NOTBOL },
16 { "STARTEND", REG_STARTEND },
21 static int test_regex_bug(void)
23 char *pat = "[^={} \t]+";
24 char *str = "={}\nfred";
28 if (regcomp(&r, pat, REG_EXTENDED | REG_NEWLINE))
29 die("failed regcomp() for pattern '%s'", pat);
30 if (regexec(&r, str, 1, m, 0))
31 die("no match of pattern '%s' to string '%s'", pat, str);
33 /* http://sourceware.org/bugzilla/show_bug.cgi?id=3957 */
34 if (m[0].rm_so == 3) /* matches '\n' when it should not */
35 die("regex bug confirmed: re-build git with NO_REGEX=1");
40 int cmd__regex(int argc, const char **argv)
48 if (argc == 2 && !strcmp(argv[1], "--bug"))
49 return test_regex_bug();
51 usage("test-tool regex --bug\n"
52 "test-tool regex <pattern> <string> [<options>]");
59 for (rf = reg_flags; rf->name; rf++)
60 if (!strcmp(*argv, rf->name)) {
65 die("do not recognize %s", *argv);
70 if (regcomp(&r, pat, flags))
71 die("failed regcomp() for pattern '%s'", pat);
72 if (regexec(&r, str, 1, m, 0))