@matheusbsbs / matheus-bagliano / commits / 0da43a685a
Fork 0

send-email: fix nasty bug in ask() function

Commit 6e18251 (send-email: refactor and ensure prompting doesn't loop forever) introduced an ask function, which unfortunately had a nasty bug. This caused it not to accept anything but the default reply to the "Who should the emails appear to be from?" prompt, and nothing but ctrl-d to the "Who should the emails be sent to?" and "Message-ID to be used as In-Reply-To for the first email?" prompts. This commit corrects the issues and adds a test to confirm the fix. Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jay Soffian committed Apr 4, 2009 at 23:23 UTC 0da43a685aa061f55ed19ea30e1d6220020059a6
2 files changed +15 -2
git-send-email.perl
+2 -2
@@ -608,7 +608,7 @@ EOT
608
609 sub ask {
610 my ($prompt, %arg) = @_;
611 - my $valid_re = $arg{valid_re} || ""; # "" matches anything
611 + my $valid_re = $arg{valid_re};
612 my $default = $arg{default};
613 my $resp;
614 my $i = 0;
@@ -624,7 +624,7 @@ sub ask {
624 if ($resp eq '' and defined $default) {
625 return $default;
626 }
627 - if ($resp =~ /$valid_re/) {
627 + if (!defined $valid_re or $resp =~ /$valid_re/) {
628 return $resp;
629 }
630 }
t/t9001-send-email.sh
+13
@@ -130,6 +130,19 @@ test_expect_success 'Show all headers' '
130 test_cmp expected-show-all-headers actual-show-all-headers
131 '
132
133 +test_expect_success 'Prompting works' '
134 + clean_fake_sendmail &&
135 + (echo "Example <from@example.com>"
136 + echo "to@example.com"
137 + echo ""
138 + ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
139 + --smtp-server="$(pwd)/fake.sendmail" \
140 + $patches \
141 + 2>errors &&
142 + grep "^From: Example <from@example.com>$" msgtxt1 &&
143 + grep "^To: to@example.com$" msgtxt1
144 +'
145 +
146 z8=zzzzzzzz
147 z64=$z8$z8$z8$z8$z8$z8$z8$z8
148 z512=$z64$z64$z64$z64$z64$z64$z64$z64