From d4c14f6a8e8ea2513897c9402ff7c57594bc24de Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 12 Apr 2024 11:33:51 -0500 Subject: [PATCH 1/5] test(response): Show backslash bug --- src/response.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/response.rs b/src/response.rs index adabf01..443181f 100644 --- a/src/response.rs +++ b/src/response.rs @@ -27,7 +27,9 @@ mod test { let input = "--hello world @moon.txt --goodbye 'walker texas' -sun"; +sun +c:\\Windows +"; let expected: Vec = vec![ crate::Argument::PassThrough("--hello".into()), crate::Argument::PassThrough("world".into()), @@ -35,6 +37,7 @@ sun"; crate::Argument::PassThrough("--goodbye".into()), crate::Argument::PassThrough("walker texas".into()), crate::Argument::PassThrough("sun".into()), + crate::Argument::PassThrough("c:Windows".into()), ]; let actual = parse_response(input, crate::PREFIX); assert_eq!(expected, actual); From 92574ef76d4019f58ba50de2347140bf17021c80 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 12 Apr 2024 11:36:48 -0500 Subject: [PATCH 2/5] test(response): Split up quote types --- src/response.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/response.rs b/src/response.rs index 443181f..b1cf627 100644 --- a/src/response.rs +++ b/src/response.rs @@ -24,18 +24,20 @@ mod test { #[test] fn sample() { - let input = "--hello world + let input = r#"--hello world @moon.txt ---goodbye 'walker texas' +--goodbye "walker texas" +'single' sun -c:\\Windows -"; +c:\Windows +"#; let expected: Vec = vec![ crate::Argument::PassThrough("--hello".into()), crate::Argument::PassThrough("world".into()), crate::Argument::PassThrough("@moon.txt".into()), crate::Argument::PassThrough("--goodbye".into()), crate::Argument::PassThrough("walker texas".into()), + crate::Argument::PassThrough("single".into()), crate::Argument::PassThrough("sun".into()), crate::Argument::PassThrough("c:Windows".into()), ]; From 1c69466b7170310ad00b8ba93816cb9f83823588 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 12 Apr 2024 11:39:51 -0500 Subject: [PATCH 3/5] test(response): Show shell comments --- src/response.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/response.rs b/src/response.rs index b1cf627..d1d581c 100644 --- a/src/response.rs +++ b/src/response.rs @@ -30,6 +30,7 @@ mod test { 'single' sun c:\Windows +# comment "#; let expected: Vec = vec![ crate::Argument::PassThrough("--hello".into()), From 690c6903d5c2c7d076a318b75c927871d0fbca45 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 12 Apr 2024 11:40:46 -0500 Subject: [PATCH 4/5] fix(response): Use Windows escaping rules Fixes #68 --- Cargo.lock | 14 +++++++------- Cargo.toml | 4 ++-- src/response.rs | 9 +++++---- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce15016..a8b9949 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,8 +57,8 @@ dependencies = [ "clap", "fs-err", "os_str_bytes", - "shlex", "wild", + "winsplit", ] [[package]] @@ -121,12 +121,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "shlex" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" - [[package]] name = "strsim" version = "0.11.0" @@ -213,3 +207,9 @@ name = "windows_x86_64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "winsplit" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ab703352da6a72f35c39a533526393725640575bb211f61987a2748323ad956" diff --git a/Cargo.toml b/Cargo.toml index 937d1dc..11ade2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,12 +118,12 @@ pre-release-replacements = [ [features] default = [] -response = ["shlex"] +response = ["dep:winsplit"] [dependencies] fs-err = "2.9.0" os_str_bytes = "6.0" -shlex = { version = "1.1.0", optional = true } +winsplit = { version = "0.1.0", optional = true } [dev-dependencies] clap = "4.5.1" diff --git a/src/response.rs b/src/response.rs index d1d581c..803ff17 100644 --- a/src/response.rs +++ b/src/response.rs @@ -3,8 +3,7 @@ /// See [Microsoft response files](https://docs.microsoft.com/en-us/cpp/build/reference/at-specify-a-compiler-response-file?view=msvc-170). #[cfg(feature = "response")] pub fn parse_response(content: &str, _prefix: char) -> Vec { - shlex::split(content) - .unwrap_or_default() + winsplit::split(content) .into_iter() .map(|s| crate::Argument::PassThrough(s.into())) .collect() @@ -38,9 +37,11 @@ c:\Windows crate::Argument::PassThrough("@moon.txt".into()), crate::Argument::PassThrough("--goodbye".into()), crate::Argument::PassThrough("walker texas".into()), - crate::Argument::PassThrough("single".into()), + crate::Argument::PassThrough("'single'".into()), crate::Argument::PassThrough("sun".into()), - crate::Argument::PassThrough("c:Windows".into()), + crate::Argument::PassThrough("c:\\Windows".into()), + crate::Argument::PassThrough("#".into()), + crate::Argument::PassThrough("comment".into()), ]; let actual = parse_response(input, crate::PREFIX); assert_eq!(expected, actual); From 4b917d39fe4418b149cf3ffd2f1a61a9d6dc9edc Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 12 Apr 2024 11:42:00 -0500 Subject: [PATCH 5/5] docs(response): Clarify quoting rules --- src/response.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/response.rs b/src/response.rs index 803ff17..53d399b 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,5 +1,8 @@ /// Parse a Microsoft response file /// +/// Quoting is subject to +/// [`CommandLineToArgvW`](https://learn.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments?view=msvc-170) +/// /// See [Microsoft response files](https://docs.microsoft.com/en-us/cpp/build/reference/at-specify-a-compiler-response-file?view=msvc-170). #[cfg(feature = "response")] pub fn parse_response(content: &str, _prefix: char) -> Vec {