Skip to content

Commit cb2922f

Browse files
moygitster
authored andcommitted
send-email: fix garbage removal after address
This is a followup over 9d33439 (send-email: only allow one address per body tag, 2017-02-20). The first iteration did allow writting Cc: <[email protected]> # garbage but did so by matching the regex ([^>]*>?), i.e. stop after the first instance of '>'. However, it did not properly deal with Cc: [email protected] # garbage Fix this using a new function strip_garbage_one_address, which does essentially what the old ([^>]*>?) was doing, but dealing with more corner-cases. Since we've allowed Cc: "Foo # Bar" <[email protected]> in previous versions, it makes sense to continue allowing it (but we still remove any garbage after it). OTOH, when an address is given without quoting, we just take the first word and ignore everything after. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent edc74bc commit cb2922f

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

git-send-email.perl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,26 @@ sub sanitize_address {
10891089

10901090
}
10911091

1092+
sub strip_garbage_one_address {
1093+
my ($addr) = @_;
1094+
chomp $addr;
1095+
if ($addr =~ /^(("[^"]*"|[^"<]*)? *<[^>]*>).*/) {
1096+
# "Foo Bar" <[email protected]> [possibly garbage here]
1097+
# Foo Bar <[email protected]> [possibly garbage here]
1098+
return $1;
1099+
}
1100+
if ($addr =~ /^(<[^>]*>).*/) {
1101+
# <[email protected]> [possibly garbage here]
1102+
# if garbage contains other addresses, they are ignored.
1103+
return $1;
1104+
}
1105+
if ($addr =~ /^([^"#,\s]*)/) {
1106+
# address without quoting: remove anything after the address
1107+
return $1;
1108+
}
1109+
return $addr;
1110+
}
1111+
10921112
sub sanitize_address_list {
10931113
return (map { sanitize_address($_) } @_);
10941114
}
@@ -1590,10 +1610,12 @@ sub send_message {
15901610
# Now parse the message body
15911611
while(<$fh>) {
15921612
$message .= $_;
1593-
if (/^(Signed-off-by|Cc): ([^>]*>?)/i) {
1613+
if (/^(Signed-off-by|Cc): (.*)/i) {
15941614
chomp;
15951615
my ($what, $c) = ($1, $2);
1596-
chomp $c;
1616+
# strip garbage for the address we'll use:
1617+
$c = strip_garbage_one_address($c);
1618+
# sanitize a bit more to decide whether to suppress the address:
15971619
my $sc = sanitize_address($c);
15981620
if ($sc eq $sender) {
15991621
next if ($suppress_cc{'self'});

t/t9001-send-email.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ cat >expected-cc <<\EOF
148148
149149
150150
151+
152+
151153
EOF
152154
"
153155

@@ -161,6 +163,8 @@ test_expect_success $PREREQ 'cc trailer with various syntax' '
161163
Cc: <[email protected]> # trailing comments are ignored
162164
Cc: <[email protected]>, <[email protected]> one address per line
163165
Cc: "Some # Body" <[email protected]> [ <also.a.comment> ]
166+
167+
164168
EOF
165169
clean_fake_sendmail &&
166170
git send-email -1 [email protected] \

0 commit comments

Comments
 (0)