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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Feb 11, 2020 at 12:19 UTC
ffbea1816dcbce12d4ffb304ddf8993ef611d4f1
2 files changed
+18
-2
mailinfo.c
+3
-2
@@ -351,9 +351,10 @@ static inline int skip_header(const struct strbuf *line, const char *hdr,
351
{
352
const char *val;
353
if (!skip_iprefix(line->buf, hdr, &val) ||
354
- *val++ != ':' ||
355
- !isspace(*val++))
354
+ *val++ != ':')
355
return 0;
356
+ while (isspace(*val))
357
+ val++;
358
*outval = val;
359
return 1;
360
}
t/t5100-mailinfo.sh
+15
@@ -213,4 +213,19 @@ test_expect_failure 'mailinfo -b separated double [PATCH]' '
213
test z"$subj" = z"Subject: [other] message"
214
'
215
216
+test_expect_success 'mailinfo handles unusual header whitespace' '
217
+ git mailinfo /dev/null /dev/null >actual <<-\EOF &&
218
+ From:Real Name <user@example.com>
219
+ Subject: extra spaces
220
+ EOF
221
+
222
+ cat >expect <<-\EOF &&
223
+ Author: Real Name
224
+ Email: user@example.com
225
+ Subject: extra spaces
226
+
227
+ EOF
228
+ test_cmp expect actual
229
+'
230
+
231
test_done