]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mailinfo: be more liberal with header whitespace
authorJeff King <peff@peff.net>
Tue, 11 Feb 2020 17:19:53 +0000 (12:19 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Feb 2020 18:20:42 +0000 (10:20 -0800)
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>
mailinfo.c
t/t5100-mailinfo.sh

index ee8d05e239fca514910439774f29d88ffabc9d72..78f06da5243c17d8f1bb09fb25088e46e72d5c30 100644 (file)
@@ -351,9 +351,10 @@ static inline int skip_header(const struct strbuf *line, const char *hdr,
 {
        const char *val;
        if (!skip_iprefix(line->buf, hdr, &val) ||
-           *val++ != ':' ||
-           !isspace(*val++))
+           *val++ != ':')
                return 0;
+       while (isspace(*val))
+               val++;
        *outval = val;
        return 1;
 }
index 9690dcad4fd5ba0148b3f6a709ab321976545db0..147e616533cfd77baa318d37fd85ebd092c141e6 100755 (executable)
@@ -213,4 +213,19 @@ test_expect_failure 'mailinfo -b separated double [PATCH]' '
        test z"$subj" = z"Subject: [other] message"
 '
 
+test_expect_success 'mailinfo handles unusual header whitespace' '
+       git mailinfo /dev/null /dev/null >actual <<-\EOF &&
+       From:Real Name <user@example.com>
+       Subject:    extra spaces
+       EOF
+
+       cat >expect <<-\EOF &&
+       Author: Real Name
+       Email: user@example.com
+       Subject: extra spaces
+
+       EOF
+       test_cmp expect actual
+'
+
 test_done