tests: diff: test parsing diffs with a new file with spaces in its path Add a test that verifies that we are able to parse patches which add a new file that has spaces in its path.
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
diff --git a/tests/diff/parse.c b/tests/diff/parse.c
index 9cdaa92..7cc4682 100644
--- a/tests/diff/parse.c
+++ b/tests/diff/parse.c
@@ -359,3 +359,21 @@ void test_diff_parse__lineinfo(void)
git_patch_free(patch);
git_diff_free(diff);
}
+
+void test_diff_parse__new_file_with_space(void)
+{
+ const char *content = PATCH_ORIGINAL_NEW_FILE_WITH_SPACE;
+ git_patch *patch;
+ git_diff *diff;
+
+ cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
+ cl_git_pass(git_patch_from_diff((git_patch **) &patch, diff, 0));
+
+ cl_assert_equal_p(patch->diff_opts.old_prefix, NULL);
+ cl_assert_equal_p(patch->delta->old_file.path, NULL);
+ cl_assert_equal_s(patch->diff_opts.new_prefix, "b/");
+ cl_assert_equal_s(patch->delta->new_file.path, "sp ace.txt");
+
+ git_patch_free(patch);
+ git_diff_free(diff);
+}
diff --git a/tests/patch/patch_common.h b/tests/patch/patch_common.h
index 3f2668d..75aab44 100644
--- a/tests/patch/patch_common.h
+++ b/tests/patch/patch_common.h
@@ -841,3 +841,12 @@
"diff --git a/binary.bin b/binary.bin\n" \
"index 27184d9..7c94f9e 100644\n" \
"Binary files a/binary.bin and b/binary.bin differ\n"
+
+#define PATCH_ORIGINAL_NEW_FILE_WITH_SPACE \
+ "diff --git a/sp ace.txt b/sp ace.txt\n" \
+ "new file mode 100644\n" \
+ "index 000000000..789819226\n" \
+ "--- /dev/null\n" \
+ "+++ b/sp ace.txt\n" \
+ "@@ -0,0 +1 @@\n" \
+ "+a\n"