git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH 1/2] send-email: fix garbage removal after address

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 24, 2017, 20:32 UTC
Message-ID
<xmqqk21svh9o.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170823102102.20120-1-git@matthieu-moy.fr>
Matthieu Moy <git@matthieu-moy.fr> writes:
Show 50 quoted lines
> 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>
> ---
> Also available as: https://github.com/git/git/pull/398
>
>  git-send-email.perl   | 26 ++++++++++++++++++++++++--
>  t/t9001-send-email.sh |  4 ++++
>  2 files changed, 28 insertions(+), 2 deletions(-)
>
> diff --git a/git-send-email.perl b/git-send-email.perl
> index fa6526986e..33a69ffe5d 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -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;
> +	}

Isn't this already covered by the first one, which allows an optional "something", followed by an optional run of SPs, in front of this exact pattern, so the case where the optional "something" does not appear and the number of optional SP is zero would exactly match the one this pattern is meant to cover.

Show 6 quoted lines
> +	if ($addr =~ /^([^"#,\s]*)/) {
> +		# address without quoting: remove anything after the address
> +		return $1;
> +	}
> +	return $addr;
> +}

By the way, these three regexps smell like they were written specifically to cover three cases you care about (perhaps the ones in your proposed log message), but what will be our response when somebody else comes next time to us and says that their favourite formatting of "Cc:" line is not covered by these rules?

Will we add yet another pattern? Where will it end? There will be a point where we instead start telling them to update the convention of their project so that it will be covered by one of the patterns we have already developed, I would imagine.

So, from that point of view, I, with devil's advocate hat on, wonder why we are not saying

	"Cc: s@k.org # cruft"?  Use "Cc: <s@k.org> # cruft" instead
	and you'd be fine.
right now, without this patch.

I do not _mind_ us trying to be extra nice for a while, and I certainly do not mind _this_ particular patch that gives us a single helper function that future "here is another way to spell cruft" rules can go, but I feel that there should be some line that lets us say that we've done enough.

Thanks.
Previous: Jacob KellerNext: Matthieu Moy
Message 9 of 13 in “git send-email Cc with cruft not working as expected”
  1. Jacob KellerAug 22, 2017
  2. Stefan BellerAug 22, 2017
  3. Jacob KellerAug 22, 2017
  4. Stefan BellerAug 22, 2017
  5. Matthieu MoyAug 23, 2017
  6. 1/2 send-email: fix garbage removal after addressMatthieu Moy, Aug 23, 2017
  7. 2/2 send-email: don't use Mail::Address, even if availableMatthieu Moy, Aug 23, 2017
  8. Jacob KellerAug 23, 2017
  9. Junio C HamanoAug 24, 2017
  10. Matthieu MoyAug 25, 2017
  11. 1/2 send-email: fix garbage removal after addressMatthieu Moy, Aug 25, 2017
  12. 2/2 send-email: don't use Mail::Address, even if availableMatthieu Moy, Aug 25, 2017
  13. Jacob KellerAug 23, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.