1- use std:: { mem, path:: PathBuf } ;
1+ use std:: { ffi :: OsString , mem, path:: PathBuf } ;
22
33use crate :: common:: SudoString ;
44
@@ -49,7 +49,7 @@ impl TryFrom<SuOptions> for SuVersionOptions {
4949#[ cfg_attr( test, derive( PartialEq ) ) ]
5050pub struct SuRunOptions {
5151 // -c
52- pub command : Option < String > ,
52+ pub command : Option < OsString > ,
5353 // -g
5454 pub group : Vec < SudoString > ,
5555 // -l
@@ -64,7 +64,7 @@ pub struct SuRunOptions {
6464 pub whitelist_environment : Vec < String > ,
6565
6666 pub user : SudoString ,
67- pub arguments : Vec < String > ,
67+ pub arguments : Vec < OsString > ,
6868}
6969
7070#[ cfg( test) ]
@@ -106,7 +106,7 @@ impl TryFrom<SuOptions> for SuRunOptions {
106106 } else {
107107 positional_args. remove ( 0 )
108108 } ;
109- let arguments = positional_args;
109+ let arguments = positional_args. into_iter ( ) . map ( OsString :: from ) . collect ( ) ;
110110
111111 Ok ( Self {
112112 command,
@@ -182,7 +182,7 @@ impl<T> IsAbsent for Vec<T> {
182182#[ derive( Debug , Default , PartialEq ) ]
183183pub ( super ) struct SuOptions {
184184 // -c
185- command : Option < String > ,
185+ command : Option < OsString > ,
186186 // -g
187187 group : Vec < SudoString > ,
188188 // -h
@@ -222,7 +222,7 @@ impl SuOptions {
222222 takes_argument : true ,
223223 set : |sudo_options, argument| {
224224 if argument. is_some ( ) {
225- sudo_options. command = argument;
225+ sudo_options. command = argument. map ( OsString :: from ) ;
226226 Ok ( ( ) )
227227 } else {
228228 Err ( "no command provided" . into ( ) )
@@ -555,7 +555,7 @@ mod tests {
555555 fn it_parses_arguments ( ) {
556556 let expected = SuAction :: Run ( SuRunOptions {
557557 user : "ferris" . into ( ) ,
558- arguments : vec ! [ "script.sh" . to_string ( ) ] ,
558+ arguments : vec ! [ "script.sh" . into ( ) ] ,
559559 ..<_ >:: default ( )
560560 } ) ;
561561
@@ -565,7 +565,7 @@ mod tests {
565565 #[ test]
566566 fn it_parses_command ( ) {
567567 let expected = SuAction :: Run ( SuRunOptions {
568- command : Some ( "'echo hi'" . to_string ( ) ) ,
568+ command : Some ( "'echo hi'" . into ( ) ) ,
569569 ..<_ >:: default ( )
570570 } ) ;
571571 assert_eq ! ( expected, parse( & [ "-c" , "'echo hi'" ] ) ) ;
@@ -574,7 +574,7 @@ mod tests {
574574 assert_eq ! ( expected, parse( & [ "--command='echo hi'" ] ) ) ;
575575
576576 let expected = SuAction :: Run ( SuRunOptions {
577- command : Some ( "env" . to_string ( ) ) ,
577+ command : Some ( "env" . into ( ) ) ,
578578 ..<_ >:: default ( )
579579 } ) ;
580580 assert_eq ! ( expected, parse( & [ "-c" , "env" ] ) ) ;
@@ -705,7 +705,7 @@ mod tests {
705705 #[ test]
706706 fn flags_after_dash ( ) {
707707 let expected = SuAction :: Run ( SuRunOptions {
708- command : Some ( "echo" . to_string ( ) ) ,
708+ command : Some ( "echo" . into ( ) ) ,
709709 login : true ,
710710 ..<_ >:: default ( )
711711 } ) ;
@@ -716,7 +716,7 @@ mod tests {
716716 fn only_positional_args_after_dashdash ( ) {
717717 let expected = SuAction :: Run ( SuRunOptions {
718718 user : "ferris" . into ( ) ,
719- arguments : vec ! [ "-c" . to_string ( ) , "echo" . to_string ( ) ] ,
719+ arguments : vec ! [ "-c" . into ( ) , "echo" . into ( ) ] ,
720720 ..<_ >:: default ( )
721721 } ) ;
722722 assert_eq ! ( expected, parse( & [ "--" , "ferris" , "-c" , "echo" ] ) ) ;
0 commit comments