Skip to content

Commit 70a7b03

Browse files
authored
Merge pull request #8558 from cakebaker/basenc_allow_non_utf8_filenames
basenc: allow non-UTF8 filenames
2 parents eb6bfce + 93706cd commit 70a7b03

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/uu/basenc/src/basenc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn uu_app() -> Command {
6363
}
6464

6565
fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> {
66-
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args.collect_lossy())?;
66+
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
6767

6868
let encodings = get_encodings();
6969
let format = encodings

tests/by-util/test_basenc.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// spell-checker: ignore (encodings) lsbf msbf
77

8-
use uutests::new_ucmd;
8+
use uutests::{at_and_ucmd, new_ucmd};
99

1010
#[test]
1111
fn test_z85_not_padded_decode() {
@@ -270,3 +270,31 @@ fn test_z85_length_check() {
270270
.succeeds()
271271
.stdout_only("12345678");
272272
}
273+
274+
#[test]
275+
fn test_file() {
276+
let (at, mut ucmd) = at_and_ucmd!();
277+
let filename = "file";
278+
279+
at.write(filename, "foo");
280+
281+
ucmd.arg(filename)
282+
.arg("--base64")
283+
.succeeds()
284+
.stdout_is("Zm9v\n");
285+
}
286+
287+
#[test]
288+
#[cfg(target_os = "linux")]
289+
fn test_file_with_non_utf8_name() {
290+
use std::os::unix::ffi::OsStringExt;
291+
let (at, mut ucmd) = at_and_ucmd!();
292+
293+
let filename = std::ffi::OsString::from_vec(vec![0xFF, 0xFE]);
294+
std::fs::write(at.plus(&filename), b"foo").unwrap();
295+
296+
ucmd.arg(filename)
297+
.arg("--base64")
298+
.succeeds()
299+
.stdout_is("Zm9v\n");
300+
}

0 commit comments

Comments
 (0)