Skip to content

fix(dotenv): drop shell-sourcing help and single-quote non-token values (#1455) - #1460

Merged
sdairs merged 1 commit into
claude/slow-queries-timestamp-name-listfrom
claude/dotenv-help-and-token-quoting
Nov 16, 2026
Merged

sdairs merged 1 commit into
claude/slow-queries-timestamp-name-listfrom
claude/dotenv-help-and-token-quoting

Conversation

@sdairs

@sdairs sdairs commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Why:

  1. local clickhouse dotenv --help taught shell sourcing (set -a; source .env; set +a), unlike local postgres dotenv and cloud service dotenv, instead of sticking to what the command writes and prints.
  2. format_dotenv_line used a narrow character denylist, leaving tabs (which fail dotenvy's line parser), shell metacharacters (;, &, |, (), <>), and backticks unquoted unless $ was also present.

What:

  • Trim the shell-sourcing instructions from local clickhouse dotenv --help in src/local/cli.rs, keeping the file target, informational preview, and in-place update behaviour.
  • Update format_dotenv_line in src/dotenv.rs to 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 \r is present.
  • Expand unit tests in src/dotenv.rs to check all three quoting tiers and round-tripping through dotenvy (both standalone and between adjacent assignments).

QA: cargo fmt --all --check, cargo clippy -p clickhousectl --all-targets -- -D warnings (default and --no-default-features), and cargo test -p clickhousectl.

Risks: Low. Plain ASCII tokens (hosts, ports, URLs, emails) remain bare; non-token values without ', \, \n, or \r switch from double-quoted or bare to single-quoted, which dotenvy, python-dotenv, Node dotenv, 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_line now 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 .env updates therefore emit e.g. CLICKHOUSE_PASSWORD='my secret#123' instead of double-quoted form.

Unit tests cover all three tiers, dotenvy round-trips (single line and multi-line files), and updated expectations for update_dotenv.

local clickhouse dotenv help no longer suggests shell sourcing (set -a; source .env); it states the command writes a file and prints an informational preview, aligned with other dotenv commands.

Reviewed by Cursor Bugbot for commit 8a274a4. Bugbot is set up for automated code reviews on this repo. Configure here.

@sdairs
sdairs requested a review from iskakaushik as a code owner November 13, 2026 22:18
@sdairs
sdairs added this pull request to stack #1285 November 13, 2026 22:43

@iskakaushik iskakaushik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@sdairs
sdairs merged commit d010b3e into main Nov 16, 2026
21 checks passed
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.

dotenv: drop shell-sourcing instructions from local help and quote non-token values safely

2 participants