-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Correctly parse arguments from environment variables #14376
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ use lazycell::LazyCell; | |
use serde::de::IntoDeserializer as _; | ||
use serde::Deserialize; | ||
use serde_untagged::UntaggedEnumVisitor; | ||
use shlex::Shlex; | ||
use time::OffsetDateTime; | ||
use toml_edit::Item; | ||
use url::Url; | ||
|
@@ -973,8 +974,8 @@ impl GlobalContext { | |
} | ||
} else { | ||
output.extend( | ||
env_val | ||
.split_whitespace() | ||
Shlex::new(env_val) | ||
.into_iter() | ||
.map(|s| (s.to_string(), def.clone())), | ||
Comment on lines
976
to
979
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need a test for this. Ideally, the PR gets split up into two commits
As discussed at https://doc.crates.io/contrib/process/working-on-cargo.html#submitting-a-pull-request There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted! Rewriting git history and using this occasion to add a test. |
||
); | ||
} | ||
|
@@ -2971,9 +2972,13 @@ fn disables_multiplexing_for_bad_curl( | |
mod tests { | ||
use super::disables_multiplexing_for_bad_curl; | ||
use super::CargoHttpConfig; | ||
use super::ConfigKey; | ||
use super::Definition; | ||
use super::GlobalContext; | ||
use super::Shell; | ||
|
||
use std::collections::HashMap; | ||
|
||
#[test] | ||
fn disables_multiplexing() { | ||
let mut gctx = GlobalContext::new(Shell::new(), "".into(), "".into()); | ||
|
@@ -3010,4 +3015,37 @@ mod tests { | |
assert_eq!(http.multiplexing, result); | ||
} | ||
} | ||
|
||
#[test] | ||
fn env_argument_parsing() { | ||
let mut gctx = GlobalContext::new(Shell::new(), "".into(), "".into()); | ||
gctx.set_search_stop_path(std::path::PathBuf::new()); | ||
|
||
let values: &[(&str, &[&str])] = &[ | ||
("VAL1", &["--path"]), | ||
("VAL2", &["--path=\"y z\""]), | ||
("VAL3", &["--path", "\"y z\""]), | ||
]; | ||
|
||
let mut env = HashMap::new(); | ||
for (key, value) in values { | ||
env.insert(format!("CARGO_{key}"), value.join(" ")); | ||
} | ||
gctx.set_env(env); | ||
|
||
for (key, value) in values { | ||
let mut args = Vec::new(); | ||
gctx.get_env_list(&ConfigKey::from_str(key), &mut args) | ||
.unwrap(); | ||
|
||
let mut expected = Vec::new(); | ||
for sub in *value { | ||
expected.push(( | ||
sub.replace("\"", ""), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Definition::Environment(format!("CARGO_{key}")), | ||
)); | ||
} | ||
assert_eq!(args, expected, "failed for key {}", key); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocked on discussion in #14381