rust-lang / rust-lang/rust

`Command::env` doesn't report an error for keys with `=` in them

Open
#122,335 5 comments 0 reactions 1 assignee View on GitHub

@tbu- is already working on this.

Since Jun 13, 2024.

C-discussion T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

fn main() {
    println!(
        "{:?}",
        std::process::Command::new("printenv")
            .arg("foo")
            .env("foo=bar", "baz")
            .output()
    );
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4c8d4bb6d9fb790591d7cf07dbf516e8

This has a stdout of bar=baz, so the foo key has value bar=baz.

Which isn't what I asked for in env, but what I asked for is invalid.

We probably shouldn't panic from a bad env call, but this program shouldn't be able to spawn without erroring.

I assume .env("foo=bar", "baz").env_remove("foo=bar") shouldn't error. (Also, not sure how non-unix platforms handle this, but this validation should presumably be platform-specific).

I'm not sure if this is a bug or just weird behavior.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.