Skip to content

Commit d0e50cb

Browse files
peffJunio C Hamano
authored andcommitted
commit: fix pretty-printing of messages with "\nencoding "
The function replace_encoding_header is given the whole commit buffer, including the commit message. When looking for the encoding header, if none was found in the header, it would locate any line in the commit message matching "\nencoding " and remove it. Instead, we now make sure to search only to the end of the header. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75c962c commit d0e50cb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

commit.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,15 +644,18 @@ static char *get_header(const struct commit *commit, const char *key)
644644
static char *replace_encoding_header(char *buf, char *encoding)
645645
{
646646
char *encoding_header = strstr(buf, "\nencoding ");
647+
char *header_end = strstr(buf, "\n\n");
647648
char *end_of_encoding_header;
648649
int encoding_header_pos;
649650
int encoding_header_len;
650651
int new_len;
651652
int need_len;
652653
int buflen = strlen(buf) + 1;
653654

654-
if (!encoding_header)
655-
return buf; /* should not happen but be defensive */
655+
if (!header_end)
656+
header_end = buf + buflen;
657+
if (!encoding_header || encoding_header >= header_end)
658+
return buf;
656659
encoding_header++;
657660
end_of_encoding_header = strchr(encoding_header, '\n');
658661
if (!end_of_encoding_header)

0 commit comments

Comments
 (0)