Skip to content

Commit d414dbc

Browse files
committed
basenc: ignore case with "--base16 --decode"
1 parent 9abf9d0 commit d414dbc

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/uu/base32/src/base_common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::io::{self, ErrorKind, Read, Seek, SeekFrom};
1111
use std::path::{Path, PathBuf};
1212
use uucore::display::Quotable;
1313
use uucore::encoding::{
14-
for_base_common::{BASE32, BASE32HEX, BASE64, BASE64URL, BASE64_NOPAD, HEXUPPER},
14+
for_base_common::{BASE32, BASE32HEX, BASE64, BASE64URL, BASE64_NOPAD, HEXUPPER_PERMISSIVE},
1515
Format, Z85Wrapper, BASE2LSBF, BASE2MSBF,
1616
};
1717
use uucore::encoding::{EncodingWrapper, SupportsFastDecodeAndEncode};
@@ -226,11 +226,11 @@ pub fn get_supports_fast_decode_and_encode(
226226

227227
match format {
228228
Format::Base16 => Box::from(EncodingWrapper::new(
229-
HEXUPPER,
229+
HEXUPPER_PERMISSIVE,
230230
BASE16_VALID_DECODING_MULTIPLE,
231231
BASE16_UNPADDED_MULTIPLE,
232232
// spell-checker:disable-next-line
233-
b"0123456789ABCDEF",
233+
b"0123456789ABCDEFabcdef",
234234
)),
235235
Format::Base2Lsbf => Box::from(EncodingWrapper::new(
236236
BASE2LSBF,

tests/by-util/test_basenc.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,24 @@ fn test_base16_decode() {
130130
.stdout_only("Hello, World!");
131131
}
132132

133+
#[test]
134+
fn test_base16_decode_lowercase() {
135+
new_ucmd!()
136+
.args(&["--base16", "-d"])
137+
.pipe_in("48656c6c6f2c20576f726c6421")
138+
.succeeds()
139+
.stdout_only("Hello, World!");
140+
}
141+
142+
#[test]
143+
fn test_base16_decode_and_ignore_garbage_lowercase() {
144+
new_ucmd!()
145+
.args(&["--base16", "-d", "-i"])
146+
.pipe_in("48656c6c6f2c20576f726c6421")
147+
.succeeds()
148+
.stdout_only("Hello, World!");
149+
}
150+
133151
#[test]
134152
fn test_base2msbf() {
135153
new_ucmd!()

0 commit comments

Comments
 (0)