@@ -17,6 +17,7 @@ use crate::os::windows::ffi::{OsStrExt, OsStringExt};
17
17
use crate :: os:: windows:: io:: { AsRawHandle , FromRawHandle , IntoRawHandle } ;
18
18
use crate :: path:: { Path , PathBuf } ;
19
19
use crate :: ptr;
20
+ use crate :: sys:: args:: { self , Arg } ;
20
21
use crate :: sys:: c;
21
22
use crate :: sys:: c:: NonZeroDWORD ;
22
23
use crate :: sys:: cvt;
@@ -27,7 +28,7 @@ use crate::sys::pipe::{self, AnonPipe};
27
28
use crate :: sys:: stdio;
28
29
use crate :: sys_common:: mutex:: StaticMutex ;
29
30
use crate :: sys_common:: process:: { CommandEnv , CommandEnvs } ;
30
- use crate :: sys_common:: { AsInner , IntoInner } ;
31
+ use crate :: sys_common:: IntoInner ;
31
32
32
33
use libc:: { c_void, EXIT_FAILURE , EXIT_SUCCESS } ;
33
34
@@ -147,7 +148,7 @@ impl AsRef<OsStr> for EnvKey {
147
148
}
148
149
}
149
150
150
- fn ensure_no_nuls < T : AsRef < OsStr > > ( str : T ) -> io:: Result < T > {
151
+ pub ( crate ) fn ensure_no_nuls < T : AsRef < OsStr > > ( str : T ) -> io:: Result < T > {
151
152
if str. as_ref ( ) . encode_wide ( ) . any ( |b| b == 0 ) {
152
153
Err ( io:: const_io_error!( ErrorKind :: InvalidInput , "nul byte found in provided data" ) )
153
154
} else {
@@ -181,14 +182,6 @@ pub struct StdioPipes {
181
182
pub stderr : Option < AnonPipe > ,
182
183
}
183
184
184
- #[ derive( Debug ) ]
185
- enum Arg {
186
- /// Add quotes (if needed)
187
- Regular ( OsString ) ,
188
- /// Append raw string without quoting
189
- Raw ( OsString ) ,
190
- }
191
-
192
185
impl Command {
193
186
pub fn new ( program : & OsStr ) -> Command {
194
187
Command {
@@ -724,15 +717,6 @@ fn zeroed_process_information() -> c::PROCESS_INFORMATION {
724
717
}
725
718
}
726
719
727
- enum Quote {
728
- // Every arg is quoted
729
- Always ,
730
- // Whitespace and empty args are quoted
731
- Auto ,
732
- // Arg appended without any changes (#29494)
733
- Never ,
734
- }
735
-
736
720
// Produces a wide string *without terminating null*; returns an error if
737
721
// `prog` or any of the `args` contain a nul.
738
722
fn make_command_line (
@@ -763,57 +747,9 @@ fn make_command_line(
763
747
764
748
for arg in args {
765
749
cmd. push ( ' ' as u16 ) ;
766
- let ( arg, quote) = match arg {
767
- Arg :: Regular ( arg) => ( arg, if force_quotes { Quote :: Always } else { Quote :: Auto } ) ,
768
- Arg :: Raw ( arg) => ( arg, Quote :: Never ) ,
769
- } ;
770
- append_arg ( & mut cmd, arg, quote) ?;
771
- }
772
- if is_batch_file {
773
- cmd. push ( b'"' as u16 ) ;
774
- }
775
- return Ok ( cmd) ;
776
-
777
- fn append_arg ( cmd : & mut Vec < u16 > , arg : & OsStr , quote : Quote ) -> io:: Result < ( ) > {
778
- // If an argument has 0 characters then we need to quote it to ensure
779
- // that it actually gets passed through on the command line or otherwise
780
- // it will be dropped entirely when parsed on the other end.
781
- ensure_no_nuls ( arg) ?;
782
- let arg_bytes = & arg. as_inner ( ) . inner . as_inner ( ) ;
783
- let ( quote, escape) = match quote {
784
- Quote :: Always => ( true , true ) ,
785
- Quote :: Auto => {
786
- ( arg_bytes. iter ( ) . any ( |c| * c == b' ' || * c == b'\t' ) || arg_bytes. is_empty ( ) , true )
787
- }
788
- Quote :: Never => ( false , false ) ,
789
- } ;
790
- if quote {
791
- cmd. push ( '"' as u16 ) ;
792
- }
793
-
794
- let mut backslashes: usize = 0 ;
795
- for x in arg. encode_wide ( ) {
796
- if escape {
797
- if x == '\\' as u16 {
798
- backslashes += 1 ;
799
- } else {
800
- if x == '"' as u16 {
801
- // Add n+1 backslashes to total 2n+1 before internal '"'.
802
- cmd. extend ( ( 0 ..=backslashes) . map ( |_| '\\' as u16 ) ) ;
803
- }
804
- backslashes = 0 ;
805
- }
806
- }
807
- cmd. push ( x) ;
808
- }
809
-
810
- if quote {
811
- // Add n backslashes to total 2n before ending '"'.
812
- cmd. extend ( ( 0 ..backslashes) . map ( |_| '\\' as u16 ) ) ;
813
- cmd. push ( '"' as u16 ) ;
814
- }
815
- Ok ( ( ) )
750
+ args:: append_arg ( & mut cmd, arg, force_quotes) ?;
816
751
}
752
+ Ok ( cmd)
817
753
}
818
754
819
755
fn make_envp ( maybe_env : Option < BTreeMap < EnvKey , OsString > > ) -> io:: Result < ( * mut c_void , Vec < u16 > ) > {
0 commit comments