Skip to content

Commit

Permalink
Correctly parse arguments from environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Aug 9, 2024
1 parent f0141c0 commit 4b152ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
9 changes: 8 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ serde_json = "1.0.120"
sha1 = "0.10.6"
sha2 = "0.10.8"
shell-escape = "0.1.5"
shlex = "1.3.0"
similar = "2.6.0"
supports-hyperlinks = "3.0.0"
snapbox = { version = "0.6.16", features = ["diff", "dir", "term-svg", "regex", "json"] }
Expand Down Expand Up @@ -192,6 +193,7 @@ serde_ignored.workspace = true
serde_json = { workspace = true, features = ["raw_value"] }
sha1.workspace = true
shell-escape.workspace = true
shlex.workspace = true
supports-hyperlinks.workspace = true
tar.workspace = true
tempfile.workspace = true
Expand Down
11 changes: 5 additions & 6 deletions src/cargo/util/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())),
);
}
Expand Down Expand Up @@ -3022,10 +3023,8 @@ mod tests {

let values: &[(&str, &[&str])] = &[
("VAL1", &["--path"]),
// FIXME: this one is parsed as `["--path=\"y", "z\""]`.
// ("VAL2", &["--path=\"y z\""]),
// FIXME: this one is parsed as `["--path", "\"y", "z\""]`.
// ("VAL3", &["--path", "\"y z\""]),
("VAL2", &["--path=\"y z\""]),
("VAL3", &["--path", "\"y z\""]),
];

let mut env = HashMap::new();
Expand Down

0 comments on commit 4b152ec

Please sign in to comment.