Merge pull request #3384 from libgit2/cmn/regex-nofail diff: don't error out on an invalid regex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/src/diff_driver.c b/src/diff_driver.c
index 9d13371..bc35189 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -97,8 +97,7 @@ static int diff_driver_add_patterns(
for (scan = regex_str; scan; scan = end) {
/* get pattern to fill in */
if ((pat = git_array_alloc(drv->fn_patterns)) == NULL) {
- error = -1;
- break;
+ return -1;
}
pat->flags = regex_flags;
@@ -117,10 +116,9 @@ static int diff_driver_add_patterns(
break;
if ((error = regcomp(&pat->re, buf.ptr, regex_flags)) != 0) {
- /* if regex fails to compile, warn? fail? */
- error = giterr_set_regex(&pat->re, error);
- regfree(&pat->re);
- break;
+ /*
+ * TODO: issue a warning
+ */
}
}
@@ -128,7 +126,8 @@ static int diff_driver_add_patterns(
(void)git_array_pop(drv->fn_patterns); /* release last item */
git_buf_free(&buf);
- return error;
+ /* We want to ignore bad patterns, so return success regardless */
+ return 0;
}
static int diff_driver_xfuncname(const git_config_entry *entry, void *payload)
diff --git a/tests/diff/drivers.c b/tests/diff/drivers.c
index e3a0014..42af38a 100644
--- a/tests/diff/drivers.c
+++ b/tests/diff/drivers.c
@@ -250,3 +250,29 @@ void test_diff_drivers__builtins(void)
git_buf_free(&expected);
git_vector_free(&files);
}
+
+void test_diff_drivers__invalid_pattern(void)
+{
+ git_config *cfg;
+ git_index *idx;
+ git_diff *diff;
+ git_patch *patch;
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+
+ g_repo = cl_git_sandbox_init("userdiff");
+ cl_git_mkfile("userdiff/.gitattributes", "*.storyboard diff=storyboard\n");
+
+ cl_git_pass(git_repository_config__weakptr(&cfg, g_repo));
+ cl_git_pass(git_config_set_string(cfg, "diff.storyboard.xfuncname", "<!--(.*?)-->"));
+
+ cl_git_mkfile("userdiff/dummy.storyboard", "");
+ cl_git_pass(git_repository_index__weakptr(&idx, g_repo));
+ cl_git_pass(git_index_add_bypath(idx, "dummy.storyboard"));
+ cl_git_mkfile("userdiff/dummy.storyboard", "some content\n");
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+
+ git_patch_free(patch);
+ git_diff_free(diff);
+}