Skip to content

Commit 22c0122

Browse files
committed
Merge branch 'sp/send-email-validate-charset' into seen
* sp/send-email-validate-charset: send-email: validate charset name in 8bit encoding prompt
2 parents bd3edf3 + ba754ef commit 22c0122

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

git-send-email.perl

Lines changed: 14 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

@@ -995,6 +996,7 @@ sub get_patch_subject {
995996
sub ask {
996997
my ($prompt, %arg) = @_;
997998
my $valid_re = $arg{valid_re};
999+
my $warn_invalid = $arg{warn_invalid};
9981000
my $default = $arg{default};
9991001
my $confirm_only = $arg{confirm_only};
10001002
my $resp;
@@ -1013,7 +1015,15 @@ sub ask {
10131015
return $default;
10141016
}
10151017
if (!defined $valid_re or $resp =~ /$valid_re/) {
1016-
return $resp;
1018+
if ($warn_invalid) {
1019+
if (find_encoding($resp)) {
1020+
return $resp;
1021+
} else {
1022+
printf STDERR __("warning: '%s' does not appear to be a valid charset name.\n"), $resp;
1023+
}
1024+
} else {
1025+
return $resp;
1026+
}
10171027
}
10181028
if ($confirm_only) {
10191029
my $yesno = $term->readline(
@@ -1052,8 +1062,9 @@ sub file_declares_8bit_cte {
10521062
foreach my $f (sort keys %broken_encoding) {
10531063
print " $f\n";
10541064
}
1055-
$auto_8bit_encoding = ask(__("Which 8bit encoding should I declare [UTF-8]? "),
1056-
valid_re => qr/.{4}/, confirm_only => 1,
1065+
$auto_8bit_encoding = ask(__("Declare which 8bit encoding to use [default: UTF-8]? "),
1066+
valid_re => qr/^\S+$/, confirm_only => 1,
1067+
warn_invalid => 1,
10571068
default => "UTF-8");
10581069
}
10591070

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)