@@ -5,6 +5,8 @@ use cargo::{self, drop_print, drop_println, CliResult, Config};
5
5
use clap:: { AppSettings , Arg , ArgMatches } ;
6
6
use itertools:: Itertools ;
7
7
use std:: collections:: HashMap ;
8
+ use std:: ffi:: OsStr ;
9
+ use std:: ffi:: OsString ;
8
10
use std:: fmt:: Write ;
9
11
10
12
use super :: commands;
@@ -241,14 +243,14 @@ fn expand_aliases(
241
243
}
242
244
( Some ( _) , None ) => {
243
245
// Command is built-in and is not conflicting with alias, but contains ignored values.
244
- if let Some ( mut values) = args. get_many :: < String > ( "" ) {
246
+ if let Some ( values) = args. get_many :: < OsString > ( "" ) {
245
247
return Err ( anyhow:: format_err!(
246
248
"\
247
249
trailing arguments after built-in command `{}` are unsupported: `{}`
248
250
249
251
To pass the arguments to the subcommand, remove `--`" ,
250
252
cmd,
251
- values. join( " " ) ,
253
+ values. map ( |s| s . to_string_lossy ( ) ) . join( " " ) ,
252
254
)
253
255
. into ( ) ) ;
254
256
}
@@ -270,7 +272,7 @@ For more information, see issue #10049 <https://github.com/rust-lang/cargo/issue
270
272
) ) ?;
271
273
}
272
274
273
- alias. extend ( args. get_many :: < String > ( "" ) . unwrap_or_default ( ) . cloned ( ) ) ;
275
+ alias. extend ( args. get_many :: < OsString > ( "" ) . unwrap_or_default ( ) . cloned ( ) ) ;
274
276
// new_args strips out everything before the subcommand, so
275
277
// capture those global options now.
276
278
// Note that an alias to an external command will not receive
@@ -346,12 +348,12 @@ fn execute_subcommand(config: &mut Config, cmd: &str, subcommand_args: &ArgMatch
346
348
return exec ( config, subcommand_args) ;
347
349
}
348
350
349
- let mut ext_args: Vec < & str > = vec ! [ cmd] ;
351
+ let mut ext_args: Vec < & OsStr > = vec ! [ OsStr :: new ( cmd) ] ;
350
352
ext_args. extend (
351
353
subcommand_args
352
- . get_many :: < String > ( "" )
354
+ . get_many :: < OsString > ( "" )
353
355
. unwrap_or_default ( )
354
- . map ( String :: as_str ) ,
356
+ . map ( OsString :: as_os_str ) ,
355
357
) ;
356
358
super :: execute_external_subcommand ( config, cmd, & ext_args)
357
359
}
@@ -400,6 +402,7 @@ pub fn cli() -> App {
400
402
} ;
401
403
App :: new ( "cargo" )
402
404
. allow_external_subcommands ( true )
405
+ . allow_invalid_utf8_for_external_subcommands ( true )
403
406
. setting ( AppSettings :: DeriveDisplayOrder )
404
407
// Doesn't mix well with our list of common cargo commands. See clap-rs/clap#3108 for
405
408
// opening clap up to allow us to style our help template
0 commit comments