From fdaf373c0e50555c16e97f5ae41db8571fcc3ba6 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 14 Mar 2024 11:27:36 +0000 Subject: [PATCH 1/2] trailer: test actual array equivalence We never test the lengths of the two arrays, so a short return from `git_message_trailers` will match erroneously. --- tests/libgit2/message/trailer.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/libgit2/message/trailer.c b/tests/libgit2/message/trailer.c index 919e10a499c..3705794fbdb 100644 --- a/tests/libgit2/message/trailer.c +++ b/tests/libgit2/message/trailer.c @@ -3,19 +3,22 @@ static void assert_trailers(const char *message, git_message_trailer *trailers) { git_message_trailer_array arr; - size_t i; + size_t i, count; int rc = git_message_trailers(&arr, message); cl_assert_equal_i(0, rc); - for(i=0; i Date: Thu, 14 Mar 2024 11:28:20 +0000 Subject: [PATCH 2/2] trailer: ensure we identify patch lines like git Git looks explicitly for `---` followed by whitespace (`isspace()`) to determine when a patch line begins in a commit message. Match that behavior. This ensures that we don't treat (say) `----` as a patch line incorrectly. --- src/libgit2/trailer.c | 2 +- tests/libgit2/message/trailer.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libgit2/trailer.c b/src/libgit2/trailer.c index 4761c9922f2..52e655914b0 100644 --- a/src/libgit2/trailer.c +++ b/src/libgit2/trailer.c @@ -158,7 +158,7 @@ static size_t find_patch_start(const char *str) const char *s; for (s = str; *s; s = next_line(s)) { - if (git__prefixcmp(s, "---") == 0) + if (git__prefixcmp(s, "---") == 0 && git__isspace(s[3])) return s - str; } diff --git a/tests/libgit2/message/trailer.c b/tests/libgit2/message/trailer.c index 3705794fbdb..09e8f6115a7 100644 --- a/tests/libgit2/message/trailer.c +++ b/tests/libgit2/message/trailer.c @@ -165,3 +165,23 @@ void test_message_trailer__invalid(void) "Another: trailer\n" , trailers); } + +void test_message_trailer__ignores_dashes(void) +{ + git_message_trailer trailers[] = { + { "Signed-off-by", "some@one.com" }, + { "Another", "trailer" }, + { NULL, NULL }, + }; + + assert_trailers( + "Message\n" + "\n" + "Markdown header\n" + "---------------\n" + "Lorem ipsum\n" + "\n" + "Signed-off-by: some@one.com\n" + "Another: trailer\n" + , trailers); +}