summaryrefslogtreecommitdiff
path: root/tests/patch
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-09-22 13:39:05 +0200
committerPatrick Steinhardt <ps@pks.im>2017-11-11 20:29:28 +0000
commit80226b5f674e6d04a4064ebc93c09fc667e8fa52 (patch)
tree536922594c92ca3fcbdbbd9e128eb6a268a2471a /tests/patch
parent3892f70d8e6e6c8483d2163763d9c8b98b6fbf0a (diff)
downloadlibgit2-80226b5f674e6d04a4064ebc93c09fc667e8fa52.tar.gz
patch_parse: allow parsing ambiguous patch headers
The git patch format allows for having unquoted paths with whitespaces inside. This format becomes ambiguous to parse, e.g. in the following example: diff --git a/file b/with spaces.txt b/file b/with spaces.txt While we cannot parse this in a correct way, we can instead use the "---" and "+++" lines to retrieve the file names, as the path is not followed by anything here but spans the complete remaining line. Because of this, we can simply bail outwhen parsing the "diff --git" header here without an actual error and then proceed to just take the paths from the other headers.
Diffstat (limited to 'tests/patch')
-rw-r--r--tests/patch/parse.c6
-rw-r--r--tests/patch/patch_common.h10
2 files changed, 16 insertions, 0 deletions
diff --git a/tests/patch/parse.c b/tests/patch/parse.c
index 8350ac2dd..a40ad7b23 100644
--- a/tests/patch/parse.c
+++ b/tests/patch/parse.c
@@ -102,3 +102,9 @@ void test_patch_parse__invalid_patches_fails(void)
strlen(PATCH_CORRUPT_MISSING_HUNK_HEADER), NULL));
}
+void test_patch_parse__files_with_whitespaces_succeeds(void)
+{
+ git_patch *patch;
+ cl_git_pass(git_patch_from_buffer(&patch, PATCH_NAME_WHITESPACE, strlen(PATCH_NAME_WHITESPACE), NULL));
+ git_patch_free(patch);
+}
diff --git a/tests/patch/patch_common.h b/tests/patch/patch_common.h
index a20ebd617..e838e6089 100644
--- a/tests/patch/patch_common.h
+++ b/tests/patch/patch_common.h
@@ -575,6 +575,16 @@
"+added line with no nl\n" \
"\\ No newline at end of file\n"
+#define PATCH_NAME_WHITESPACE \
+ "diff --git a/file with spaces.txt b/file with spaces.txt\n" \
+ "index 9432026..83759c0 100644\n" \
+ "--- a/file with spaces.txt\n" \
+ "+++ b/file with spaces.txt\n" \
+ "@@ -0,3 +0,2 @@\n" \
+ " and this\n" \
+ "-is additional context\n" \
+ " below it!\n" \
+
#define PATCH_CORRUPT_GIT_HEADER \
"diff --git a/file.txt\n" \
"index 9432026..0f39b9a 100644\n" \