diff options
| author | Junio C Hamano <gitster@pobox.com> | 2026-03-12 10:56:05 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-03-12 10:56:05 -0700 |
| commit | 99da9348352a4e79246c17fd6cef425af801e309 (patch) | |
| tree | f764ce347449d69cf6aa6971295d10b04eded16e | |
| parent | 898549142353fa105ad2c466a52e497620d12bb3 (diff) | |
| parent | c52f085a477c8eece87821c5bbc035e5a900eb12 (diff) | |
| download | git-99da9348352a4e79246c17fd6cef425af801e309.tar.xz | |
Merge branch 'sp/send-email-validate-charset'
"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
| -rwxr-xr-x | git-send-email.perl | 25 | ||||
| -rwxr-xr-x | t/t9001-send-email.sh | 2 |
2 files changed, 23 insertions, 4 deletions
diff --git a/git-send-email.perl b/git-send-email.perl index 1448b44097..bb8ddd1eef 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -23,6 +23,7 @@ use Getopt::Long; use Git::LoadCPAN::Error qw(:try); use Git; use Git::I18N; +use Encode qw(find_encoding); Getopt::Long::Configure qw/ pass_through /; @@ -1051,9 +1052,27 @@ if (!defined $auto_8bit_encoding && scalar %broken_encoding) { foreach my $f (sort keys %broken_encoding) { print " $f\n"; } - $auto_8bit_encoding = ask(__("Which 8bit encoding should I declare [UTF-8]? "), - valid_re => qr/.{4}/, confirm_only => 1, - default => "UTF-8"); + while (1) { + my $encoding = ask( + __("Declare which 8bit encoding to use [default: UTF-8]? "), + valid_re => qr/^\S+$/, + default => "UTF-8"); + next unless defined $encoding; + if (find_encoding($encoding)) { + $auto_8bit_encoding = $encoding; + last; + } + my $yesno = ask( + sprintf( + __("'%s' does not appear to be a valid charset name. Use it anyway [y/N]? "), + $encoding), + valid_re => qr/^(?:y|n)/i, + default => "n"); + if (defined $yesno && $yesno =~ /^y/i) { + $auto_8bit_encoding = $encoding; + last; + } + } } if (!$force) { diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index e56e0c8d77..24f6c76aee 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1691,7 +1691,7 @@ test_expect_success $PREREQ 'asks about and fixes 8bit encodings' ' email-using-8bit >stdout && grep "do not declare a Content-Transfer-Encoding" stdout && grep email-using-8bit stdout && - grep "Which 8bit encoding" stdout && + grep "Declare which 8bit encoding to use" stdout && grep -E "Content|MIME" msgtxt1 >actual && test_cmp content-type-decl actual ' |
