Skip to content

fix: escape single quotes in forwarded env values - #535

Open
Dev-next-gen wants to merge 2 commits into
CodSpeedHQ:mainfrom
Dev-next-gen:fix/env-file-single-quote
Open

Dev-next-gen wants to merge 2 commits into
CodSpeedHQ:mainfrom
Dev-next-gen:fix/env-file-single-quote

Conversation

@Dev-next-gen

Copy link
Copy Markdown

I was reading the history of run_with_env.rs and noticed that 340d9ab fixed values with spaces by wrapping them in single quotes (export {k}='{v}'), but nothing escapes a single quote inside the value. Such a value closes the quoting early, the env file no longer sources, and the benchmark never starts.

The values written there include the --profile-folder path and the user's PATH, so this is reachable from the CLI. On current main (37eba9e), on Linux:

$ CODSPEED_PROFILER_ENABLED=false codspeed exec --skip-upload --mode walltime --profile-folder "/tmp/it's here" -- echo hello

› Running the benchmarks

/tmp/.tmpW2PMqD: line 27: unexpected EOF while looking for matching `''
  ✗ failed to execute the benchmark process: exit status: 2

With this branch the same command runs the benchmark and exits 0.

The fix escapes embedded quotes as '\'', so values without a quote produce exactly the same line as before. The memory executor goes through the same create_env_file via prefix_command_with_env, so it gets the fix too. I only ran the walltime path end to end.

I added a unit test that writes an env file with a quoted value, sources it with bash and checks the value comes back unchanged. It fails on main with the error above and passes with the change. cargo fmt --check is clean and clippy reports nothing in this file.

AI tools used

340d9ab wrapped the injected values in single quotes so that spaces
survive `source`, but a value that itself contains a single quote still
closes the quoting early. The env file then fails to source with
"unexpected EOF while looking for matching `''", and the benchmark never
runs.

The values come from `--profile-folder` and the user's PATH, so a
profile folder like "/tmp/it's here" is enough to break walltime and
memory runs. Escape embedded quotes as '\'' so the value is passed
through verbatim.
@greptile-apps

greptile-apps Bot commented Sep 13, 2026

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

The production fix appears safe to merge, with a non-blocking portability issue in the new regression test.

Fix All in Claude CodeFindings

  1. P2 Temporary path is unquoted
Fix with agent prompt
### Issue 1
src/executor/helpers/run_with_env.rs:84-91
If the host temporary directory contains whitespace or shell metacharacters, Bash parses the interpolated path incorrectly and this regression test fails even though value escaping is correct. Pass the path as a separate shell argument so it is sourced without reparsing its contents.

```suggestion
        let output = Command::new("bash")
            .arg("-c")
            .arg("source \"$1\" && printf %s \"$CODSPEED_TEST_VALUE\"")
            .arg("bash")
            .arg(env_file.path())
            .output()
            .unwrap();
```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

  • Replaces embedded single quotes with the standard shell-safe '\'' sequence.
  • Preserves the existing output for values without single quotes.
  • Verifies that a quoted profile-like value survives sourcing, though the test should shell-quote its temporary file path.

Reviews (1) · Last reviewed commit: "fix: escape single quotes in forwarded e..."

Comment thread src/executor/helpers/run_with_env.rs
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant