]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
basenc: --base16: support lower case hex digits
authorPádraig Brady <P@draigBrady.com>
Mon, 23 Oct 2023 11:51:19 +0000 (12:51 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 23 Oct 2023 13:04:38 +0000 (14:04 +0100)
* src/basenc.c (base16_decode_ctx): Convert to uppercase
before converting from hex.
* tests/basenc/basenc.pl: Add a test case.
* NEWS: Mention the change in behavior.
Addresses https://bugs.gnu.org/66698

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

diff --git a/NEWS b/NEWS
index 93f98b99d8b5ed539ea6c675e72e8744d85ae6f8..1dfeb7390aa66d36e733085772f5f12eef1f4cb2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   base32 and base64 no longer require padding when decoding.
   Previously an error was given for non padded encoded data.
 
+  basenc --base16 -d now supports lower case hexadecimal characters.
+  Previously an error was given for lower case hex digits.
+
   ls --dired now implies long format output without hyperlinks enabled,
   and will take precedence over previously specified formats or hyperlink mode.
 
index 12021e90080bfe6c25355aaeb54ef3ba5c206548..74cf03a49b72742f3c6dd3f12721dc9a5eb44302 100644 (file)
@@ -577,7 +577,7 @@ base16_decode_ctx (struct base_decode_context *ctx,
           continue;
         }
 
-      int nib = *in++;
+      int nib = c_toupper (*in++);
       if ('0' <= nib && nib <= '9')
         nib -= '0';
       else if ('A' <= nib && nib <= 'F')
index de20d2dbcf1947e9d7a5926de39e84791e311f2f..2b0e79e9325fc73f29bd297eabf0e34fca2466ed 100755 (executable)
@@ -159,6 +159,7 @@ my @Tests =
  ['b16_7', '--base16 -d',     {IN=>'G'}, {EXIT=>1},
   {ERR=>"$prog: invalid input\n"}],
  ['b16_8', '--base16 -d',     {IN=>"AB\nCD"}, {OUT=>"\xAB\xCD"}],
+ ['b16_9', '--base16 -d',     {IN=>lc ($base16_out)},  {OUT=>$base16_in}],