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.
This commit is contained in:
Edward Thomson
2024-03-14 11:28:20 +00:00
parent fdaf373c0e
commit d488817076
2 changed files with 21 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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);
}