Repository navigation
fix(dotenv): drop shell-sourcing help and single-quote non-token values (#1455) - #1460
Merged
sdairs merged 1 commit intoNov 16, 2026
Conversation
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.
Why:
local clickhouse dotenv --helptaught shell sourcing (set -a; source .env; set +a), unlikelocal postgres dotenvandcloud service dotenv, instead of sticking to what the command writes and prints.format_dotenv_lineused a narrow character denylist, leaving tabs (which faildotenvy's line parser), shell metacharacters (;,&,|,(),<>), and backticks unquoted unless$was also present.What:
local clickhouse dotenv --helpinsrc/local/cli.rs, keeping the file target, informational preview, and in-place update behaviour.format_dotenv_lineinsrc/dotenv.rsto write bare only non-empty plain ASCII tokens ([A-Za-z0-9_./:@%+-]+), single-quote any other value without',\,\n, or\r, and fall back to double quotes when',\,\n, or\ris present.src/dotenv.rsto check all three quoting tiers and round-tripping throughdotenvy(both standalone and between adjacent assignments).QA:
cargo fmt --all --check,cargo clippy -p clickhousectl --all-targets -- -D warnings(default and--no-default-features), andcargo test -p clickhousectl.Risks: Low. Plain ASCII tokens (hosts, ports, URLs, emails) remain bare; non-token values without
',\,\n, or\rswitch from double-quoted or bare to single-quoted, whichdotenvy,python-dotenv, Nodedotenv, Docker--env-file, and POSIX shells all read literally.Closes #1455
Note
Low Risk
Behavior change is limited to how non-token values are quoted when writing .env files; common connection strings stay bare and round-trip tests cover dotenvy parsing.
Overview
format_dotenv_linenow picks the weakest quoting that still keeps values literal: bare[A-Za-z0-9_./:@%+-]tokens, single quotes when the value has no',\, or newlines (so spaces,#,$, tabs, and shell metacharacters are no longer left bare or forced into double quotes), and double quotes only when escapes are required. In-place.envupdates therefore emit e.g.CLICKHOUSE_PASSWORD='my secret#123'instead of double-quoted form.Unit tests cover all three tiers,
dotenvyround-trips (single line and multi-line files), and updated expectations forupdate_dotenv.local clickhouse dotenvhelp no longer suggests shell sourcing (set -a; source .env); it states the command writes a file and prints an informational preview, aligned with otherdotenvcommands.Reviewed by Cursor Bugbot for commit 8a274a4. Bugbot is set up for automated code reviews on this repo. Configure here.