basenc: --base16: support lower case hex digits

* 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
This commit is contained in:
Pádraig Brady
2023-10-23 12:51:19 +01:00
parent 2e0dcd87bf
commit d733f2ec26
3 changed files with 5 additions and 1 deletions

3
NEWS
View File

@@ -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.

View 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')

View File

@@ -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}],