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