1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-05 14:06:15 +02:00

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: <foo@example.com> # garbage

but did so by matching the regex ([^>]*>?), i.e. stop after the first
instance of '>'. However, it did not properly deal with

  Cc: foo@example.com # 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" <foobar@example.com>

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 <git@matthieu-moy.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Matthieu Moy 2017-08-23 12:21:01 +02:00 committed by Junio C Hamano
parent edc74bc7f0
commit cb2922fe4b
2 changed files with 28 additions and 2 deletions

View File

@ -1089,6 +1089,26 @@ sub sanitize_address {
}
sub strip_garbage_one_address {
my ($addr) = @_;
chomp $addr;
if ($addr =~ /^(("[^"]*"|[^"<]*)? *<[^>]*>).*/) {
# "Foo Bar" <foobar@example.com> [possibly garbage here]
# Foo Bar <foobar@example.com> [possibly garbage here]
return $1;
}
if ($addr =~ /^(<[^>]*>).*/) {
# <foo@example.com> [possibly garbage here]
# if garbage contains other addresses, they are ignored.
return $1;
}
if ($addr =~ /^([^"#,\s]*)/) {
# address without quoting: remove anything after the address
return $1;
}
return $addr;
}
sub sanitize_address_list {
return (map { sanitize_address($_) } @_);
}
@ -1590,10 +1610,12 @@ sub send_message {
# Now parse the message body
while(<$fh>) {
$message .= $_;
if (/^(Signed-off-by|Cc): ([^>]*>?)/i) {
if (/^(Signed-off-by|Cc): (.*)/i) {
chomp;
my ($what, $c) = ($1, $2);
chomp $c;
# strip garbage for the address we'll use:
$c = strip_garbage_one_address($c);
# sanitize a bit more to decide whether to suppress the address:
my $sc = sanitize_address($c);
if ($sc eq $sender) {
next if ($suppress_cc{'self'});

View File

@ -148,6 +148,8 @@ cat >expected-cc <<\EOF
!two@example.com!
!three@example.com!
!four@example.com!
!five@example.com!
!six@example.com!
EOF
"
@ -161,6 +163,8 @@ test_expect_success $PREREQ 'cc trailer with various syntax' '
Cc: <two@example.com> # trailing comments are ignored
Cc: <three@example.com>, <not.four@example.com> one address per line
Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
Cc: five@example.com # not.six@example.com
Cc: six@example.com, not.seven@example.com
EOF
clean_fake_sendmail &&
git send-email -1 --to=recipient@example.com \