{"thread":{"id":"47250","subject":"[PATCH v2] git-send-email: fix --cc-cmd get_maintainer.pl regression","startedAt":"2017-11-20T11:44:48Z","lastAt":"2017-11-20T11:44:48Z","messageCount":1,"participants":["Alex Bennée"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"332902","messageId":"20171120114435.17989-1-alex.bennee@linaro.org","threadId":"47250","inReplyTo":null,"subject":"[PATCH v2] git-send-email: fix --cc-cmd get_maintainer.pl regression","fromName":"Alex Bennée","fromEmail":"alex.bennee@linaro.org","sentAt":"2017-11-20T11:44:35Z","receivedAt":"2017-11-20T11:44:48Z","isPatch":true,"sender":{"key":"alex.bennee@linaro.org","avatar":"https://avatars.githubusercontent.com/u/22458?v=4"},"body":"Since the removal of Mail::Address from git-send-email certain address\npatterns returned by common get_maintainer.pl scripts now fail to get\ncorrectly parsed by the built-in Git::parse_mailboxes. Specifically\nthe patterns with embedded parenthesis fail. For example from the\nLinux kernel MAINTAINERS:\n\n  KERNEL VIRTUAL MACHINE FOR ARM (KVM/arm)\n  L:\tlinux-arm-kernel@lists.infradead.org (moderated for non-subscribers)\n  L:\tkvmarm@lists.cs.columbia.edu\n\nWhich is returned by get_maintainers.pl as:\n\n  linux-arm-kernel@lists.infradead.org (moderated list:KERNEL VIRTUAL MACHINE FOR ARM (KVM/arm))\n  kvmarm@lists.cs.columbia.edu (open list:KERNEL VIRTUAL MACHINE FOR ARM (KVM/arm))\n\nHowever Git::parse_mailboxes code mangles the address, appending the\ntrailing parenthesis to the email address to the address part causing\nit to fail validation:\n\n   error: unable to extract a valid address from: linux-arm-kernel@lists.infradead.org) (moderated list:KERNEL VIRTUAL MACHINE FOR ARM (KVM/arm)\n   error: unable to extract a valid address from: kvmarm@lists.cs.columbia.edu) (open list:KERNEL VIRTUAL MACHINE FOR ARM (KVM/arm)\n\nAs this is a common pattern which was handled by Mail::Address I've\nfixed the regression by explicitly capturing a trailing bracket and\nappending it to the comment token.\n\nNB: the t9001.sh test doesn't explicitly wrap the call to the --cc-cmd\nin a \"$(pwd)/expected-cc-script.sh\" which fails due to the space to\nthe full-path of the test. It is currently ambiguous as to if --cc-cmd\nneeds to handle this. I suspect it is not an edge case that has come\nup in real-world usage as git-send-email is usually run directly from\na git directory with scripts generally in a ./script/get_maintainer.pl\npath.\n\nFixes: cc9075067776ebd34cc08f31bf78bb05f12fd879\nSigned-off-by: Alex Bennée <alex.bennee@linaro.org>\nCc: Eric Sunshine <sunshine@sunshineco.com>\n---\n perl/Git.pm           |  3 +++\n t/t9000/test.pl       |  3 ++-\n t/t9001-send-email.sh | 16 ++++++++++++++++\n 3 files changed, 21 insertions(+), 1 deletion(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex ffa09ace9..9b17de1cc 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -936,6 +936,9 @@ sub parse_mailboxes {\n \t\t\t$end_of_addr_seen = 0;\n \t\t} elsif ($token =~ /^\\(/) {\n \t\t\tpush @comment, $token;\n+\t\t} elsif ($token =~ /^\\)/) {\n+\t\t        my $nested_comment = pop @comment;\n+\t\t\tpush @comment, \"$nested_comment$token\";\n \t\t} elsif ($token eq \"<\") {\n \t\t\tpush @phrase, (splice @address), (splice @buffer);\n \t\t} elsif ($token eq \">\") {\ndiff --git a/t/t9000/test.pl b/t/t9000/test.pl\nindex dfeaa9c65..b01642a0d 100755\n--- a/t/t9000/test.pl\n+++ b/t/t9000/test.pl\n@@ -35,7 +35,8 @@ my @success_list = (q[Jane],\n \tq['Jane 'Doe' <jdoe@example.com>],\n \tq[Jane@:;\\.,()<>Doe <jdoe@example.com>],\n \tq[Jane <jdoe@example.com> Doe],\n-\tq[<jdoe@example.com> Jane Doe]);\n+\tq[<jdoe@example.com> Jane Doe],\n+\tq[jdoe@example.com (open list:for thing (foo/bar))]);\n \n my @known_failure_list = (q[Jane\\ Doe <jdoe@example.com>],\n \tq[\"Doe, Ja\"ne <jdoe@example.com>],\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 4d261c2a9..fa783eb87 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -172,6 +172,22 @@ test_expect_success $PREREQ 'cc trailer with various syntax' '\n \ttest_cmp expected-cc commandline1\n '\n \n+test_expect_success $PREREQ 'cc trailer with get_maintainer output' '\n+        write_script expected-cc-script.sh <<-EOF &&\n+echo \"One Person <one@example.com> (supporter:THIS (FOO/bar))\"\n+echo \"Two Person <two@example.com> (maintainer:THIS THING)\"\n+echo \"Third List <three@example.com> (moderated list:THIS THING (FOO/bar))\"\n+echo \"<four@example.com> (moderated list:FOR THING)\"\n+echo \"five@example.com (open list:FOR THING (FOO/bar))\"\n+echo \"six@example.com (open list)\"\n+EOF\n+\tclean_fake_sendmail &&\n+\tgit send-email -1 --to=recipient@example.com \\\n+\t\t--cc-cmd=./expected-cc-script.sh \\\n+\t\t--smtp-server=\"$(pwd)/fake.sendmail\" &&\n+\ttest_cmp expected-cc commandline1\n+'\n+\n test_expect_success $PREREQ 'setup expect' \"\n cat >expected-show-all-headers <<\\EOF\n 0001-Second.patch\n-- \n2.15.0\n\n"}]}