fix(tmux): zsh source path + dotenv outer quote stripping#29
Merged
Conversation
zsh's POSIX `.` builtin does not search the current directory unless `.` is in `$PATH` — the default macOS shell is zsh, so the bare `. '.env'` form silently failed there with "no such file or directory" even after the cd-first fix from #18. Services in tmux windows ended up without the per-slot env: `ECLUSE_*` vars from the per-slug preamble were fine, but anything from `.env`, `.env.local`, or `.env.ecluse` that wasn't duplicated into the preamble was lost. build_source_preamble now emits `. './.env'` (and the same for `.env.local`/`.env.ecluse`). The `./` prefix is POSIX-correct and works in bash, zsh, and dash. Adds three regression tests covering the correct prefix, the missing-files-skip behavior, and the empty-tree case. Fixes #27
parse_env_file treated everything after `=` as the literal value,
which round-tripped `FOO="bar"` as the 5-character value `"bar"`
(quotes included) when the value got re-emitted in the per-slug
tmux preamble as `export FOO='"bar"'`. Downstream consumers that
check against a literal string (e.g. `z.literal("development")`)
would reject the quoted value, breaking any framework using
conventional dotenv `KEY="value"` style.
A matched outer pair of `"..."` or `'...'` is now stripped — the
standard dotenv convention where `FOO=bar` and `FOO="bar"` mean the
same thing. Unmatched quotes (`FOO="oops`), inner escaped quotes
(`MSG="hello \"world\""`), and unquoted values containing literal
quote chars or `=` (`URL=postgres://x:5433/db?a=b`) are preserved
verbatim, so URLs and query strings round-trip unchanged.
Adds seven regression tests covering double, single, unquoted,
unmatched, inner-escaped, empty-quoted, and bare-quote-char cases.
Fixes #28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #27 and #28 — two separate but related bugs in the tmux env-sourcing path that landed in 0.3.0.
#27 — zsh:
. '.env'silently failsAfter the cd-first fix in #18, the tmux startup command sources env files with the POSIX
.builtin and a relative path:In bash,
. '.env'searches the current directory and works. In zsh (default on macOS since Catalina),.does NOT search cwd unless.is in$PATH— it logs.: no such file or directory: .envand continues silently. Per-slot env never loads.Fix: emit
. './.env'. The./prefix is POSIX-correct and works in bash, zsh, and dash.#28 — preamble emits double-quoted values
parse_env_filetook everything after=as the literal value. A.envlineFOO="bar"round-tripped asexport FOO='"bar"'in the per-slug preamble, leaking the literal"characters into the runtime env. Strict consumers likez.literal("development")rejected the quoted string.Fix: strip a matched outer pair of
"..."or'...'from values during parse. Unquoted values, URL/path strings with embedded=or?, unmatched quotes, and inner escaped quotes are all preserved verbatim. This is the standard dotenv convention.Why #28 was masked until 0.3.0
The cd-ordering bug from #26 meant the per-slot env never loaded at all — so nobody noticed the preamble itself was malformed. #27 then exposed it on zsh; bash users would have hit it as soon as the preamble started loading.
Tests
src/process.rs: 3 tests forbuild_source_preamblecovering the./prefix, missing-file skipping, and empty-tree behavior. Includes a negative assertion that pins the regression — the bare. '.env'form must never be re-emitted.src/env.rs: 7 tests forparse_env_filecovering double, single, unquoted, unmatched, inner-escaped, empty-quoted, and bare-quote-char values.cargo fmt --check,cargo clippy -- -D warnings,cargo test --bin ecluse(439 unit tests passing) all green. Thedocker_e2eintegration suite is unrelated to these changes (it needs a pre-pulled test image and skips elsewhere).Test plan
tmux capture-pane -t ecluse-<slug>:<service> -p -S -100shows nono such file or directory: .envlinesecho "$ECLUSE_<NAME>_PORT"resolves to the slot's port even afterecluse up <other-slug>ran in another terminal.envlineONYX_ENVIRONMENT="development"results in a runtime env where[ "$ONYX_ENVIRONMENT" = development ]is true (no quotes).envlineDATABASE_URL=postgres://x:5433/db?a=bround-trips unchanged