]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
basenc: --base16: also allow lower case with --ignore-garbage
authorPádraig Brady <P@draigBrady.com>
Wed, 25 Oct 2023 13:04:00 +0000 (14:04 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 25 Oct 2023 13:04:00 +0000 (14:04 +0100)
* src/basenc.c (isbase16): Also return true for lower case.
* tests/basenc/basenc.pl: Add a test case.
Reported by Paul Eggert.

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

index 74cf03a49b72742f3c6dd3f12721dc9a5eb44302..b47bd013fdab264ce27b39767bb245c5e4fbfc2e 100644 (file)
@@ -520,7 +520,7 @@ base32hex_decode_ctx_wrapper (struct base_decode_context *ctx,
 static bool
 isbase16 (char ch)
 {
-  return ('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'F');
+  return isxdigit (to_uchar (ch));
 }
 
 static int
@@ -529,12 +529,13 @@ base16_length (int len)
   return len * 2;
 }
 
-static const char base16[16] = "0123456789ABCDEF";
 
 static void
 base16_encode (char const *restrict in, idx_t inlen,
                char *restrict out, idx_t outlen)
 {
+  static const char base16[16] = "0123456789ABCDEF";
+
   while (inlen--)
     {
       unsigned char c = *in;
index 2b0e79e9325fc73f29bd297eabf0e34fca2466ed..3efe373007387752fb97e24326602fd3d8ec436f 100755 (executable)
@@ -160,6 +160,7 @@ my @Tests =
   {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}],
+ ['b16_10', '--base16 -d -i', {IN=>lc ($base16_out)},  {OUT=>$base16_in}],