Skip to content

Commit d52adf1

Browse files
chriscoolgitster
authored andcommitted
trailer: display a trailer without its trailing newline
Trailers passed to the parse_trailer() function often have a trailing newline. When erroring out, we should display the invalid trailer properly, that means without any trailing newline. Helped-by: Junio C Hamano <[email protected]> Helped-by: Jeff King <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2887103 commit d52adf1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

trailer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,12 @@ static int parse_trailer(struct strbuf *tok, struct strbuf *val, const char *tra
583583
strbuf_addch(&seps, '=');
584584
len = strcspn(trailer, seps.buf);
585585
strbuf_release(&seps);
586-
if (len == 0)
587-
return error(_("empty trailer token in trailer '%s'"), trailer);
586+
if (len == 0) {
587+
int l = strlen(trailer);
588+
while (l > 0 && isspace(trailer[l - 1]))
589+
l--;
590+
return error(_("empty trailer token in trailer '%.*s'"), l, trailer);
591+
}
588592
if (len < strlen(trailer)) {
589593
strbuf_add(tok, trailer, len);
590594
strbuf_trim(tok);

0 commit comments

Comments
 (0)