commit: don't forget the last header field When we moved the logic to handle the first one, wrong loop logic was kept in place which meant we still finished early. But we now notice it because we're not reading past the last LF we find. This was not noticed before as the last field in the tested commit was multi-line which does not trigger the early break.
diff --git a/src/commit.c b/src/commit.c
index 453506d..8faef07 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -568,7 +568,7 @@ int git_commit_header_field(git_buf *out, const git_commit *commit, const char *
git_buf_sanitize(out);
- while ((eol = strchr(buf, '\n')) && eol[1] != '\0') {
+ while ((eol = strchr(buf, '\n'))) {
/* We can skip continuations here */
if (buf[0] == ' ') {
buf = eol + 1;
diff --git a/tests/commit/parse.c b/tests/commit/parse.c
index 733fbae..3e1670e 100644
--- a/tests/commit/parse.c
+++ b/tests/commit/parse.c
@@ -453,10 +453,17 @@ cpxtDQQMGYFpXK/71stq\n\
cl_git_pass(git_commit_header_field(&buf, commit, "gpgsig"));
cl_assert_equal_s(gpgsig, buf.ptr);
+ git_buf_clear(&buf);
cl_git_fail_with(GIT_ENOTFOUND, git_commit_header_field(&buf, commit, "awesomeness"));
cl_git_fail_with(GIT_ENOTFOUND, git_commit_header_field(&buf, commit, "par"));
+ git_commit__free(commit);
+ cl_git_pass(parse_commit(&commit, passing_commit_cases[0]));
+
+ cl_git_pass(git_commit_header_field(&buf, commit, "committer"));
+ cl_assert_equal_s("Vicent Marti <tanoku@gmail.com> 1273848544 +0200", buf.ptr);
+
git_buf_free(&buf);
git_commit__free(commit);
}