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

Correctly parse arguments from environment variables #14376

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Aug 9, 2024

Fixes #14381.

The current parsing doesn't correctly handle arguments like --x="y z". To be noted: if you don't want the dependency, I can write a parser by hand too, shouldn't take many lines of code to do.

r? @epage

@rustbot rustbot added A-configuration Area: cargo config files and env vars S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 9, 2024
@GuillaumeGomez GuillaumeGomez force-pushed the parse-args-from-env-var branch from a1db1f6 to ed6a168 Compare August 9, 2024 10:08
Comment on lines 976 to 979
output.extend(
env_val
.split_whitespace()
Shlex::new(env_val)
.into_iter()
.map(|s| (s.to_string(), def.clone())),
Copy link
Contributor

Choose a reason for hiding this comment

The 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

  • The first adds the test, showing the bad behavior
  • This commit updates the test showing the good behavior

As discussed at https://doc.crates.io/contrib/process/working-on-cargo.html#submitting-a-pull-request

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted! Rewriting git history and using this occasion to add a test.

@epage
Copy link
Contributor

epage commented Aug 9, 2024

I'm unsure what the compatibility guarantees are around this. @ehuss if you have any insight, it'd be appreciated.

In general, we recommend starting with an issue. That way we make sure we are all on the same page (e.g. the definition of the problem in this PR is unclear) and, if we go through multiple possible PRs for the problem (which is common enough), the conversation on the problem and solution space is centralized rather than split among all of the PRs.

@GuillaumeGomez GuillaumeGomez force-pushed the parse-args-from-env-var branch from ed6a168 to 4b152ec Compare August 9, 2024 19:21
@GuillaumeGomez
Copy link
Member Author

I opened #14381 too.

let mut expected = Vec::new();
for sub in *value {
expected.push((
sub.replace("\"", ""),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shlex removes (double) quotes. Not sure whether or not it's a good thing. If it's not the expected behaviour, I can implement a simple shell parser which keeps them.

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-configuration Area: cargo config files and env vars S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

environment variables are not parsed correctly
3 participants