threads / patch / 41733

patchsend-email: ignore trailing whitespace in mailrc alias file

Subject: [PATCH] send-email: ignore trailing whitespace in mailrc alias file

## tl;dr

2 messages between Mar 17, 2016 and Mar 17, 2016. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Stefan Beller· Mar 17, 2016, 22:08 UTC · lore
From: Jeff King <peff@peff.net>

This fixes send-email which would not work with mailrc alias files which had trailing whitespaces.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
Show 7 quoted lines
> On Thu, Mar 17, 2016 at 10:47:50AM -0700, Stefan Beller wrote:
>
> sent from git-send-email with a corrupt .mailrc file.
> 
> Great, but could probably use a better commit message. ;P
> 
> -Peff

Uhm, yes. Why do you ask? ;) I forgot again that it is too late to edit the patch when send-email asks:

> Send this email? ([y]es|[n]o|[q]uit|[a]ll): 
as it has read the patch from disk and keeps it in memory I assume?

I just wrote the commit message as I would do, but offer you to claim authorship for that perl stuff. So in case you'd want to reword that, I'd ask you to that. Also asking for your signoff. (But apart from that I consider this patch final.)

Thanks, Stefan

Show changes to git-send-email.perl +1 −1
diff --git a/git-send-email.perl b/git-send-email.perl
index d356901..c45b22a 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -533,7 +533,7 @@ my %parse_alias = (
 			$aliases{$alias} = \@addr
 		}}},
 	mailrc => sub { my $fh = shift; while (<$fh>) {
-		if (/^alias\s+(\S+)\s+(.*)$/) {
+		if (/^alias\s+(\S+)\s+(.*?)\s*$/) {
 			# spaces delimit multiple addresses
 			$aliases{$1} = [ quotewords('\s+', 0, $2) ];
 		}}},
Jeff King· Mar 17, 2016, 23:58 UTC · re: Stefan Beller · lore

Re: [PATCH] send-email: ignore trailing whitespace in mailrc alias file

On Thu, Mar 17, 2016 at 03:08:16PM -0700, Stefan Beller wrote:
> I just wrote the commit message as I would do, but offer you to claim
> authorship for that perl stuff. So in case you'd want to reword that,
> I'd ask you to that.  Also asking for your signoff. (But apart from
> that I consider this patch final.)

Yeah, I am happy to take the credit/blame when somebody inevitably shows a case where this does the wrong thing (I say inevitable because I assume that is the fate of all regexes -- to one day be proven to miss a corner case).

But surely you know that my commit messages are more verbose than that. :)

Here's what I would have written:
-- >8 --
Subject: [PATCH] send-email: ignore trailing whitespace in mailrc alias file

The regex for parsing mailrc considers everything after the second whitespace to be the email address, up to the end of the line. We have to include whitespace there, because you may have multiple space-separated addresses, each with their own internal quoting.

But if there is trailing whitespace, we include that, too. This confuses quotewords() when we try to split the individual addresses, and we end up storing "undef" in our alias list. Later parts of the code then access that, generating perl warnings.

Let's tweak our regex to throw away any trailing whitespace on each line.

Signed-off-by: Jeff King <peff@peff.net>
---
 git-send-email.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to git-send-email.perl +1 −1
diff --git a/git-send-email.perl b/git-send-email.perl
index d356901..c45b22a 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -533,7 +533,7 @@ my %parse_alias = (
 			$aliases{$alias} = \@addr
 		}}},
 	mailrc => sub { my $fh = shift; while (<$fh>) {
-		if (/^alias\s+(\S+)\s+(.*)$/) {
+		if (/^alias\s+(\S+)\s+(.*?)\s*$/) {
 			# spaces delimit multiple addresses
 			$aliases{$1} = [ quotewords('\s+', 0, $2) ];
 		}}},
-- 
2.8.0.rc3.378.gf2f7872

← back to recent threads