]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
base64,base32: fix 'extra operand' error message
authorAssaf Gordon <assafgordon@gmail.com>
Wed, 19 Dec 2018 08:02:32 +0000 (01:02 -0700)
committerAssaf Gordon <assafgordon@gmail.com>
Tue, 1 Jan 2019 23:32:27 +0000 (16:32 -0700)
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.

NEWS
src/basenc.c
tests/misc/base64.pl
tests/misc/basenc.pl

diff --git a/NEWS b/NEWS
index 6963fe3055ce24e891c836a6f38fe62df44e7249..2bbbdabf1b3cc56748b11014b83ed0ff59df05f7 100644 (file)
--- 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
index 49aa35aa0332760f43e7d78de7e8f1546e33a1aa..d0eaef0c24b974c571c7827ab9cc3f68a73d3345 100644 (file)
@@ -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);
     }
 
index 0eb8cf4984033ea37c03e4ffc862641efaca0e00..a544558cb9dc46cc9ebae1d48fd7507195465c05 100755 (executable)
@@ -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")
index e3bba74a9dac15f5e278597c34ebca35ea98fe26..d632cf5700e1f80486a3f4f726bfe045c6a810fd 100755 (executable)
@@ -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=>""}],