send-email: handle adjacent RFC 2047-encoded words properly
The RFC says that they are to be concatenated after decoding (i.e. the intervening whitespace is ignored). Signed-off-by: Роман Донченко <dpb@corrigendum.ru> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Роман Донченко committed
Dec 14, 2014 at 18:59 UTC
ab47e2a583917ecef5da269cc640f8359c8467ac
2 files changed
+23
-10
git-send-email.perl
+16
-10
@@ -912,17 +912,23 @@ $time = time - scalar $#files;
912
sub unquote_rfc2047 {
913
local ($_) = @_;
914
my $charset;
915
- s{$re_encoded_word}{
916
- $charset = $1;
917
- my $encoding = $2;
918
- my $text = $3;
919
- if ($encoding eq 'q' || $encoding eq 'Q') {
920
- $text =~ s/_/ /g;
921
- $text =~ s/=([0-9A-F]{2})/chr(hex($1))/egi;
922
- $text;
923
- } else {
924
- $&; # other encodings not supported yet
915
+ my $sep = qr/[ \t]+/;
916
+ s{$re_encoded_word(?:$sep$re_encoded_word)*}{
917
+ my @words = split $sep, $&;
918
+ foreach (@words) {
919
+ m/$re_encoded_word/;
920
+ $charset = $1;
921
+ my $encoding = $2;
922
+ my $text = $3;
923
+ if ($encoding eq 'q' || $encoding eq 'Q') {
924
+ $_ = $text;
925
+ s/_/ /g;
926
+ s/=([0-9A-F]{2})/chr(hex($1))/egi;
927
+ } else {
928
+ # other encodings not supported yet
929
+ }
930
}
931
+ join '', @words;
932
}eg;
933
return wantarray ? ($_, $charset) : $_;
934
}
t/t9001-send-email.sh
+7
@@ -240,6 +240,13 @@ test_expect_success $PREREQ 'non-ascii self name is suppressed' "
240
'non_ascii_self_suppressed'
241
"
242
243
+# This name is long enough to force format-patch to split it into multiple
244
+# encoded-words, assuming it uses UTF-8 with the "Q" encoding.
245
+test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
246
+ test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
247
+ 'long_non_ascii_self_suppressed'
248
+"
249
+
250
test_expect_success $PREREQ 'sanitized self name is suppressed' "
251
test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
252
'self_name_sanitized_suppressed'