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 --- Cargo.lock | 3 ++- Cargo.toml | 1 + src/args.rs | 13 ++++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46581a3..e9cb31b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -350,6 +350,7 @@ dependencies = [ "log", "nom", "regex", + "shlex", "tempfile", ] diff --git a/Cargo.toml b/Cargo.toml index 450b2f0..4677d37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ lazy_static = "1.5.0" log = "0.4.22" nom = "7.1.3" regex = "1.11.0" +shlex = "1.3.0" [dev-dependencies] tempfile = "3.13.0" 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