Skip to content

Commit ffbea18

Browse files
peffgitster
authored andcommitted
mailinfo: be more liberal with header whitespace
RFC822 and friends allow arbitrary whitespace after the colon of a header and before the values. I.e.: Subject:foo Subject: foo Subject: foo all have the subject "foo". But mailinfo requires exactly one space. This doesn't seem to be bothering anybody, but it is pickier than the standard specifies. And we can easily just soak up arbitrary whitespace there in our parser, so let's do so. Note that the test covers both too little and too much whitespace, but the "too much" case already works fine (because we later eat leading and trailing whitespace from the values). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f447d02 commit ffbea18

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

mailinfo.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,10 @@ static inline int skip_header(const struct strbuf *line, const char *hdr,
351351
{
352352
const char *val;
353353
if (!skip_iprefix(line->buf, hdr, &val) ||
354-
*val++ != ':' ||
355-
!isspace(*val++))
354+
*val++ != ':')
356355
return 0;
356+
while (isspace(*val))
357+
val++;
357358
*outval = val;
358359
return 1;
359360
}

t/t5100-mailinfo.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,19 @@ test_expect_failure 'mailinfo -b separated double [PATCH]' '
213213
test z"$subj" = z"Subject: [other] message"
214214
'
215215

216+
test_expect_success 'mailinfo handles unusual header whitespace' '
217+
git mailinfo /dev/null /dev/null >actual <<-\EOF &&
218+
From:Real Name <[email protected]>
219+
Subject: extra spaces
220+
EOF
221+
222+
cat >expect <<-\EOF &&
223+
Author: Real Name
224+
225+
Subject: extra spaces
226+
227+
EOF
228+
test_cmp expect actual
229+
'
230+
216231
test_done

0 commit comments

Comments
 (0)