summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-10-17 18:33:12 +0200
committerGitHub <noreply@github.com>2019-10-17 18:33:12 +0200
commitc9464bf7ae182506883f94b87918386023ef568e (patch)
tree94cc2643ff95c1d22e5d5c0c8411c6c07769b216
parent4c0dea5a7ff31de704093e2f8f46ed45f58e51c3 (diff)
parent11de594f85479e4804b07dc4f7b33cfe9212bea0 (diff)
downloadlibgit2-c9464bf7ae182506883f94b87918386023ef568e.tar.gz
Merge pull request #5273 from dlax/parse-diff-without-extended-headers
patch_parse: handle patches without extended headers
-rw-r--r--src/patch_parse.c1
-rw-r--r--tests/diff/parse.c10
-rw-r--r--tests/patch/patch_common.h10
3 files changed, 21 insertions, 0 deletions
diff --git a/src/patch_parse.c b/src/patch_parse.c
index 51c4bb200..126918249 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -389,6 +389,7 @@ static const parse_header_transition transitions[] = {
{ "index " , STATE_DIFF, STATE_INDEX, parse_header_git_index },
{ "index " , STATE_END, STATE_INDEX, parse_header_git_index },
+ { "--- " , STATE_DIFF, STATE_PATH, parse_header_git_oldpath },
{ "--- " , STATE_INDEX, STATE_PATH, parse_header_git_oldpath },
{ "+++ " , STATE_PATH, STATE_END, parse_header_git_newpath },
{ "GIT binary patch" , STATE_INDEX, STATE_END, NULL },
diff --git a/tests/diff/parse.c b/tests/diff/parse.c
index 7d9f4b2e5..b004d1e23 100644
--- a/tests/diff/parse.c
+++ b/tests/diff/parse.c
@@ -98,6 +98,16 @@ void test_diff_parse__empty_file(void)
git_diff_free(diff);
}
+void test_diff_parse__no_extended_headers(void)
+{
+ const char *content = PATCH_NO_EXTENDED_HEADERS;
+ git_diff *diff;
+
+ cl_git_pass(git_diff_from_buffer(
+ &diff, content, strlen(content)));
+ git_diff_free(diff);
+}
+
void test_diff_parse__invalid_patches_fails(void)
{
test_parse_invalid_diff(PATCH_CORRUPT_MISSING_NEW_FILE);
diff --git a/tests/patch/patch_common.h b/tests/patch/patch_common.h
index 690e0a662..d730d142c 100644
--- a/tests/patch/patch_common.h
+++ b/tests/patch/patch_common.h
@@ -895,3 +895,13 @@
"+++ b/test-file\r\n" \
"@@ -0,0 +1 @@\r\n" \
"+a contents\r\n"
+
+#define PATCH_NO_EXTENDED_HEADERS \
+ "diff --git a/file b/file\n" \
+ "--- a/file\n" \
+ "+++ b/file\n" \
+ "@@ -1,3 +1,3 @@\n" \
+ " a\n" \
+ "-b\n" \
+ "+bb\n" \
+ " c\n"