1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 11:36:16 +00:00

Merge branch 'master' of github.com:uutils/coreutils into base32-clap

This commit is contained in:
Ricardo Iglesias 2021-04-25 22:36:26 -07:00
commit 99c13f202e
52 changed files with 407 additions and 55 deletions

View file

@ -1,4 +1,5 @@
use crate::common::util::*;
use std::ffi::OsStr;
#[test]
fn test_directory() {
@ -84,3 +85,18 @@ fn test_no_args() {
fn test_too_many_args() {
expect_error(vec!["a", "b", "c"]);
}
fn test_invalid_utf8_args(os_str: &OsStr) {
let test_vec = vec![os_str.to_os_string()];
new_ucmd!().args(&test_vec).succeeds().stdout_is("fo<EFBFBD>o\n");
}
#[cfg(any(unix, target_os = "redox"))]
#[test]
fn invalid_utf8_args_unix() {
use std::os::unix::ffi::OsStrExt;
let source = [0x66, 0x6f, 0x80, 0x6f];
let os_str = OsStr::from_bytes(&source[..]);
test_invalid_utf8_args(os_str);
}

View file

@ -20,6 +20,7 @@ use std::str::from_utf8;
use std::thread::sleep;
use std::time::Duration;
use tempfile::TempDir;
use uucore::{Args, InvalidEncodingHandling};
#[cfg(windows)]
static PROGNAME: &str = concat!(env!("CARGO_PKG_NAME"), ".exe");
@ -751,7 +752,8 @@ impl UCommand {
panic!("{}", ALREADY_RUN);
}
self.comm_string.push_str(" ");
self.comm_string.push_str(arg.as_ref().to_str().unwrap());
self.comm_string
.push_str(arg.as_ref().to_str().unwrap_or_default());
self.raw.arg(arg.as_ref());
self
}
@ -762,9 +764,15 @@ impl UCommand {
if self.has_run {
panic!("{}", MULTIPLE_STDIN_MEANINGLESS);
}
for s in args {
let strings = args
.iter()
.map(|s| s.as_ref().to_os_string())
.collect_str(InvalidEncodingHandling::Ignore)
.accept_any();
for s in strings {
self.comm_string.push_str(" ");
self.comm_string.push_str(s.as_ref().to_str().unwrap());
self.comm_string.push_str(&s);
}
self.raw.args(args.as_ref());