From: Assaf Gordon Date: Wed, 19 Dec 2018 08:02:32 +0000 (-0700) Subject: base64,base32: fix 'extra operand' error message X-Git-Tag: v8.31~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67c537b91cc80397401fcb02718f81c85ab6638b;p=thirdparty%2Fcoreutils.git base64,base32: fix 'extra operand' error message In the following invocation, 'a' is the input file, and 'b' is the extra operand: $ base64 a b Report 'b' in the error message instead of 'a': $ base64 a b base64: extra operand 'b' Discussed in https://lists.gnu.org/r/coreutils/2018-12/msg00008.html . * src/basenc.c (main): If there is more than one non-option operand, report the second one (assuming the first is a the input file name). * tests/misc/base64.pl: Add tests. * tests/misc/basenc.pl: Adjust expectedc error message in tests. * NEWS: Mention bugfix. --- diff --git a/NEWS b/NEWS index 6963fe3055..2bbbdabf1b 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,10 @@ GNU coreutils NEWS -*- outline -*- sync no longer fails for write-only file arguments. [bug introduced with argument support to sync in coreutils-8.24] + In 'base64 a b', and likewise for base32, the tool now correctly + diagnoses 'b' as the extra operand, not 'a'. + [bug introduced in coreutils-5.3.0] + ** Changes in behavior echo now always processes backslash escapes when the POSIXLY_CORRECT diff --git a/src/basenc.c b/src/basenc.c index 49aa35aa03..d0eaef0c24 100644 --- a/src/basenc.c +++ b/src/basenc.c @@ -1220,7 +1220,7 @@ main (int argc, char **argv) if (argc - optind > 1) { - error (0, 0, _("extra operand %s"), quote (argv[optind])); + error (0, 0, _("extra operand %s"), quote (argv[optind+1])); usage (EXIT_FAILURE); } diff --git a/tests/misc/base64.pl b/tests/misc/base64.pl index 0eb8cf4984..a544558cb9 100755 --- a/tests/misc/base64.pl +++ b/tests/misc/base64.pl @@ -62,6 +62,7 @@ my @Tests; sub gen_tests($) { my ($prog) = @_; + my $try_help = "Try '$prog --help' for more information.\n"; @Tests= ( ['empty', {IN=>''}, {OUT=>""}], @@ -113,6 +114,12 @@ sub gen_tests($) ['b4k-1', '--decode', {IN=>$a3k_nl[1]}, {OUT=>'a' x (3072+0)}], ['b4k-2', '--decode', {IN=>$a3k_nl[2]}, {OUT=>'a' x (3072+0)}], ['b4k-3', '--decode', {IN=>$a3k_nl[3]}, {OUT=>'a' x (3072+0)}], + + ['ext-op1', 'a b', {IN=>''}, {EXIT=>1}, + {ERR => "$prog: extra operand 'b'\n" . $try_help}], + # Again, with more option arguments + ['ext-op2', '-di --wrap=40 a b', {IN=>''}, {EXIT=>1}, + {ERR => "$prog: extra operand 'b'\n" . $try_help}], ); if ($prog eq "base64") diff --git a/tests/misc/basenc.pl b/tests/misc/basenc.pl index e3bba74a9d..d632cf5700 100755 --- a/tests/misc/basenc.pl +++ b/tests/misc/basenc.pl @@ -81,9 +81,8 @@ my @Tests = ['noenc', '', {IN=>''}, {EXIT=>1}, {ERR=>"$prog: missing encoding type\n" . $try_help }], - ## TODO: Fix to "B" (this is a bug in the original base64.c:1064 ['extra', '--base64 A B', {IN=>''}, {EXIT=>1}, - {ERR=>"$prog: extra operand 'A'\n" . $try_help}], + {ERR=>"$prog: extra operand 'B'\n" . $try_help}], ['empty1', '--base64', {IN=>''}, {OUT=>""}],