Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(response): Use Windows escaping rules #69

Merged
merged 5 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 15 additions & 5 deletions src/response.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/// 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<crate::Argument> {
shlex::split(content)
.unwrap_or_default()
winsplit::split(content)
.into_iter()
.map(|s| crate::Argument::PassThrough(s.into()))
.collect()
Expand All @@ -24,17 +26,25 @@ mod test {

#[test]
fn sample() {
let input = "--hello world
let input = r#"--hello world
@moon.txt
--goodbye 'walker texas'
sun";
--goodbye "walker texas"
'single'
sun
c:\Windows
# comment
"#;
let expected: Vec<crate::Argument> = 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()),
crate::Argument::PassThrough("#".into()),
crate::Argument::PassThrough("comment".into()),
];
let actual = parse_response(input, crate::PREFIX);
assert_eq!(expected, actual);
Expand Down
Loading