mailinfo: do not concatenate charset= attribute values from mime headers

"Content-type: text/plain; charset=UTF-8" header should not appear twice in the input, but it is always better to gracefully deal with such a case. The current code concatenates the value to the values we have seen previously, producing nonsense such as "utf8UTF-8". Instead of concatenating, forget the previous value and use the last value we see. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 17, 2012 at 14:17 UTC 176943b9658b1fa9ae3972156100d831d19c3576
6 files changed +32 -4
builtin/mailinfo.c
+2 -3
@@ -160,10 +160,9 @@ static int slurp_attr(const char *line, const char *name, struct strbuf *attr)
160 const char *ends, *ap = strcasestr(line, name);
161 size_t sz;
162
163 - if (!ap) {
164 - strbuf_setlen(attr, 0);
163 + strbuf_setlen(attr, 0);
164 + if (!ap)
165 return 0;
166 - }
166 ap += strlen(name);
167 if (*ap == '"') {
168 ap++;
t/t5100-mailinfo.sh
+1 -1
@@ -11,7 +11,7 @@ test_expect_success 'split sample box' \
11 'git mailsplit -o. "$TEST_DIRECTORY"/t5100/sample.mbox >last &&
12 last=`cat last` &&
13 echo total is $last &&
14 - test `cat last` = 16'
14 + test `cat last` = 17'
15
16 check_mailinfo () {
17 mail=$1 opt=$2
t/t5100/info0017 new
+5
@@ -0,0 +1,5 @@
1 +Author: A U Thor
2 +Email: a.u.thor@example.com
3 +Subject: A E I O U
4 +Date: Mon, 17 Sep 2012 14:23:44 -0700
5 +
t/t5100/msg0017 new
+2
@@ -0,0 +1,2 @@
1 +New content here
2 +
t/t5100/patch0017 new
+6
@@ -0,0 +1,6 @@
1 +diff --git a/foo b/foo
2 +index e69de29..d95f3ad 100644
3 +--- a/foo
4 ++++ b/foo
5 +@@ -0,0 +1 @@
6 ++New content
t/t5100/sample.mbox
+16
@@ -683,3 +683,19 @@ index e69de29..d95f3ad 100644
683 @@ -0,0 +1 @@
684 +content
685
686 +From nobody Mon Sep 17 00:00:00 2001
687 +From: A U Thor <a.u.thor@example.com>
688 +Subject: A E I O U
689 +Date: Mon, 17 Sep 2012 14:23:44 -0700
690 +MIME-Version: 1.0
691 +Content-Type: text/plain; charset="iso-2022-jp"
692 +Content-type: text/plain; charset="UTF-8"
693 +
694 +New content here
695 +
696 +diff --git a/foo b/foo
697 +index e69de29..d95f3ad 100644
698 +--- a/foo
699 ++++ b/foo
700 +@@ -0,0 +1 @@
701 ++New content