basenc: allow non-UTF8 filenames

This commit is contained in:
Daniel Hofstetter 2025-09-05 10:54:51 +02:00
parent 303a211044
commit 93706cd68c
2 changed files with 30 additions and 2 deletions

View file

@ -63,7 +63,7 @@ pub fn uu_app() -> Command {
}
fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> {
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args.collect_lossy())?;
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let encodings = get_encodings();
let format = encodings

View file

@ -5,7 +5,7 @@
// spell-checker: ignore (encodings) lsbf msbf
use uutests::new_ucmd;
use uutests::{at_and_ucmd, new_ucmd};
#[test]
fn test_z85_not_padded_decode() {
@ -270,3 +270,31 @@ fn test_z85_length_check() {
.succeeds()
.stdout_only("12345678");
}
#[test]
fn test_file() {
let (at, mut ucmd) = at_and_ucmd!();
let filename = "file";
at.write(filename, "foo");
ucmd.arg(filename)
.arg("--base64")
.succeeds()
.stdout_is("Zm9v\n");
}
#[test]
#[cfg(target_os = "linux")]
fn test_file_with_non_utf8_name() {
use std::os::unix::ffi::OsStringExt;
let (at, mut ucmd) = at_and_ucmd!();
let filename = std::ffi::OsString::from_vec(vec![0xFF, 0xFE]);
std::fs::write(at.plus(&filename), b"foo").unwrap();
ucmd.arg(filename)
.arg("--base64")
.succeeds()
.stdout_is("Zm9v\n");
}