summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/patch_parse.c5
-rw-r--r--tests/diff/parse.c21
2 files changed, 24 insertions, 2 deletions
diff --git a/src/patch_parse.c b/src/patch_parse.c
index f5275947d..d993c0311 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -562,8 +562,9 @@ static int parse_hunk_body(
int newlines = hunk->hunk.new_lines;
for (;
- ctx->remain_len > 4 && (oldlines || newlines) &&
- memcmp(ctx->line, "@@ -", 4) != 0;
+ ctx->remain_len > 1 &&
+ (oldlines || newlines) &&
+ (ctx->remain_len <= 4 || memcmp(ctx->line, "@@ -", 4) != 0);
parse_advance_line(ctx)) {
int origin;
diff --git a/tests/diff/parse.c b/tests/diff/parse.c
index b79b19e8e..35870594a 100644
--- a/tests/diff/parse.c
+++ b/tests/diff/parse.c
@@ -225,3 +225,24 @@ void test_diff_parse__foreach_works_with_parsed_patch(void)
git_diff_free(diff);
}
+
+void test_diff_parse__parsing_minimal_patch_succeeds(void)
+{
+ const char patch[] =
+ "diff --git a/obj1 b/obj2\n"
+ "index 1234567..7654321 10644\n"
+ "--- a/obj1\n"
+ "+++ b/obj2\n"
+ "@@ -1 +1 @@\n"
+ "-a\n"
+ "+\n";
+ git_buf buf = GIT_BUF_INIT;
+ git_diff *diff;
+
+ cl_git_pass(git_diff_from_buffer(&diff, patch, strlen(patch)));
+ cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
+ cl_assert_equal_s(patch, buf.ptr);
+
+ git_diff_free(diff);
+ git_buf_free(&buf);
+}