From ad2d35f273403469e64ca8ccc3d2ba594609fa30 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Wed, 18 Dec 2024 23:09:38 -0700 Subject: quote things in generated MAKEFLAGS to avoid suffering --- src/args.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index 57ac84c..8489c2d 100644 --- a/src/args.rs +++ b/src/args.rs @@ -173,7 +173,10 @@ impl Args { } else { env_makeflags }; - let env_makeflags = env_makeflags.split_whitespace().map(OsString::from); + let env_makeflags = shlex::split(&env_makeflags) + .expect("Bad args?") + .into_iter() + .map(OsString::from); // per the structopt docs, the first argument will be used as the binary name, // so we need to make sure it goes in before MAKEFLAGS let arg_0 = args.next().unwrap_or_else(|| env!("CARGO_PKG_NAME").into()); @@ -246,9 +249,9 @@ impl Args { let macros = self .targets_or_macros .iter() - .map(|x| x.as_ref()) - .filter(|x: &&str| x.contains('=')) - .collect::>() + .map(|x| shlex::try_quote(x).expect("Bad quoting?")) + .filter(|x| x.contains('=')) + .collect::>() .join(" "); let mut result = String::new(); @@ -557,6 +560,6 @@ mod test { no_print_directory: true, targets_or_macros: vec!["V=1".into()], }; - assert_eq!(args.makeflags(), "--no-print-directory V=1"); + assert_eq!(args.makeflags(), "--no-print-directory 'V=1'"); } } -- cgit v1.2.3