File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323use Git::LoadCPAN::Error qw( :try) ;
2424use Git;
2525use Git::I18N;
26+ use Encode qw( find_encoding) ;
2627
2728Getopt::Long::Configure qw/ pass_through / ;
2829
@@ -995,6 +996,7 @@ sub get_patch_subject {
995996sub 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
Original file line number Diff line number Diff 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'
You can’t perform that action at this time.
0 commit comments