mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Fix base64/base32/basenc to handle non-UTF-8 filenames
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
// spell-checker:ignore hexupper lsbf msbf unpadded nopad aGVsbG8sIHdvcmxkIQ
|
||||
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
use std::ffi::OsString;
|
||||
use std::fs::File;
|
||||
use std::io::{self, ErrorKind, Read, Seek, SeekFrom};
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -44,14 +45,14 @@ pub mod options {
|
||||
|
||||
impl Config {
|
||||
pub fn from(options: &clap::ArgMatches) -> UResult<Self> {
|
||||
let to_read = match options.get_many::<String>(options::FILE) {
|
||||
let to_read = match options.get_many::<OsString>(options::FILE) {
|
||||
Some(mut values) => {
|
||||
let name = values.next().unwrap();
|
||||
|
||||
if let Some(extra_op) = values.next() {
|
||||
return Err(UUsageError::new(
|
||||
BASE_CMD_PARSE_ERROR,
|
||||
translate!("base-common-extra-operand", "operand" => extra_op.quote()),
|
||||
translate!("base-common-extra-operand", "operand" => extra_op.to_string_lossy().quote()),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -143,6 +144,7 @@ pub fn base_app(about: &'static str, usage: &str) -> Command {
|
||||
Arg::new(options::FILE)
|
||||
.index(1)
|
||||
.action(ArgAction::Append)
|
||||
.value_parser(clap::value_parser!(OsString))
|
||||
.value_hint(clap::ValueHint::FilePath),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,9 +2,25 @@
|
||||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
#[cfg(target_os = "linux")]
|
||||
use uutests::at_and_ucmd;
|
||||
use uutests::new_ucmd;
|
||||
use uutests::util::TestScenario;
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_base64_non_utf8_paths() {
|
||||
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"hello world").unwrap();
|
||||
|
||||
ucmd.arg(&filename)
|
||||
.succeeds()
|
||||
.stdout_is("aGVsbG8gd29ybGQ=\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encode() {
|
||||
let input = "hello, world!";
|
||||
|
||||
Reference in New Issue
Block a user