Skip to content

Commit a537e3e

Browse files
committed
Merge branch 'sp/send-email-validate-charset' into next
"git send-email" has learned to be a bit more careful when it accepts charset to use from the end-user, to avoid 'y' (mistaken 'yes' when expecting a charset like 'UTF-8') and other nonsense. * sp/send-email-validate-charset: send-email: validate charset name in 8bit encoding prompt
2 parents 2a47df2 + c52f085 commit a537e3e

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

git-send-email.perl

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Git::LoadCPAN::Error qw(:try);
2424
use Git;
2525
use Git::I18N;
26+
use Encode qw(find_encoding);
2627

2728
Getopt::Long::Configure qw/ pass_through /;
2829

@@ -1051,9 +1052,27 @@ sub file_declares_8bit_cte {
10511052
foreach my $f (sort keys %broken_encoding) {
10521053
print " $f\n";
10531054
}
1054-
$auto_8bit_encoding = ask(__("Which 8bit encoding should I declare [UTF-8]? "),
1055-
valid_re => qr/.{4}/, confirm_only => 1,
1056-
default => "UTF-8");
1055+
while (1) {
1056+
my $encoding = ask(
1057+
__("Declare which 8bit encoding to use [default: UTF-8]? "),
1058+
valid_re => qr/^\S+$/,
1059+
default => "UTF-8");
1060+
next unless defined $encoding;
1061+
if (find_encoding($encoding)) {
1062+
$auto_8bit_encoding = $encoding;
1063+
last;
1064+
}
1065+
my $yesno = ask(
1066+
sprintf(
1067+
__("'%s' does not appear to be a valid charset name. Use it anyway [y/N]? "),
1068+
$encoding),
1069+
valid_re => qr/^(?:y|n)/i,
1070+
default => "n");
1071+
if (defined $yesno && $yesno =~ /^y/i) {
1072+
$auto_8bit_encoding = $encoding;
1073+
last;
1074+
}
1075+
}
10571076
}
10581077
10591078
if (!$force) {

t/t9001-send-email.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
16911691
email-using-8bit >stdout &&
16921692
grep "do not declare a Content-Transfer-Encoding" stdout &&
16931693
grep email-using-8bit stdout &&
1694-
grep "Which 8bit encoding" stdout &&
1694+
grep "Declare which 8bit encoding to use" stdout &&
16951695
grep -E "Content|MIME" msgtxt1 >actual &&
16961696
test_cmp content-type-decl actual
16971697
'

0 commit comments

Comments
 (0)