diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 94e12f451..6df282de2 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -7,6 +7,7 @@ use clap::{crate_version, Arg, ArgAction, ArgMatches, Command}; use std::error::Error; +use std::ffi::OsString; use std::fmt; use std::fs::File; use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; @@ -243,18 +244,20 @@ impl Options { /// Preprocess command line arguments and expand shortcuts. For example, "-7" is expanded to /// "--tabs=7" and "-1,3" to "--tabs=1 --tabs=3". -fn expand_shortcuts(args: &[String]) -> Vec { +fn expand_shortcuts(args: Vec) -> Vec { let mut processed_args = Vec::with_capacity(args.len()); for arg in args { - if arg.starts_with('-') && arg[1..].chars().all(is_digit_or_comma) { - arg[1..] - .split(',') - .filter(|s| !s.is_empty()) - .for_each(|s| processed_args.push(format!("--tabs={s}"))); - } else { - processed_args.push(arg.to_string()); + if let Some(arg) = arg.to_str() { + if arg.starts_with('-') && arg[1..].chars().all(is_digit_or_comma) { + arg[1..] + .split(',') + .filter(|s| !s.is_empty()) + .for_each(|s| processed_args.push(OsString::from(format!("--tabs={s}")))); + continue; + } } + processed_args.push(arg); } processed_args @@ -262,9 +265,7 @@ fn expand_shortcuts(args: &[String]) -> Vec { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - - let matches = uu_app().try_get_matches_from(expand_shortcuts(&args))?; + let matches = uu_app().try_get_matches_from(expand_shortcuts(args.collect()))?; expand(&Options::new(&matches)?) }