Hello Berny,
On 2018-12-21 12:32 a.m., Bernhard Voelker wrote:
Still, I think a user-visible fix, so I'd squash in something like:
[...]
thus I suggest:
- Subject: [PATCH] base64: fix 'extra operand' error message
+ Subject: [PATCH] base32,base64: fix 'extra operand' error message
[...]
FWIW: 'src/base64.c' should mention 'base32' in its title line.
Maybe in a separate patch (below)?
All good suggestions.
Please see the attached updated patch (containing two commits: the
extra-op fix and your second patch), rebased against the latest git
master.
regards,
- assaf
>From b251a89c65f0e68ef9fa3387455016ff92501bc4 Mon Sep 17 00:00:00 2001
From: Assaf Gordon <[email protected]>
Date: Wed, 19 Dec 2018 01:02:32 -0700
Subject: [PATCH 1/2] 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.
---
NEWS | 4 ++++
src/basenc.c | 2 +-
tests/misc/base64.pl | 7 +++++++
tests/misc/basenc.pl | 3 +--
4 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/NEWS b/NEWS
index 6963fe305..2bbbdabf1 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 49aa35aa0..d0eaef0c2 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 0eb8cf498..a544558cb 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 e3bba74a9..d632cf570 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=>""}],
--
2.11.0
>From 185ae7653f45a39ded8fe8cd78bfb3a1fe6e8e49 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <[email protected]>
Date: Fri, 21 Dec 2018 08:31:00 +0100
Subject: [PATCH 2/2] maint: mention base32 in the title line of common
basenc.c
* src/basenc.c: Do the above, and remove a redundant comment.
---
src/basenc.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/basenc.c b/src/basenc.c
index d0eaef0c2..3ce1328a2 100644
--- a/src/basenc.c
+++ b/src/basenc.c
@@ -1,8 +1,6 @@
-/* Base64 encode/decode strings or files.
+/* Base64, base32, and similar encoding/decoding strings or files.
Copyright (C) 2004-2018 Free Software Foundation, Inc.
- This file is part of Base64.
-
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
--
2.11.0