fix/config: parse env_files with the dotenv convention #64

Merged
pti merged 3 commits from fix/config-dotenv-env-files into main 2026-10-19 15:49:46 +02:00
Owner

env_files were parsed literally, so SONARQUBE_TOKEN with surrounding double quotes reached the upstream MCP server with the quotes included and failed auth with Not authorized, which cost an hour of debugging today. resolveEnv now follows the dotenv convention: an optional leading export prefix is stripped, matching single or double quotes are removed from values, inside double quotes only the three escapes backslash-quote, backslash-backslash and backslash-n are processed while single quotes stay fully literal, an unquoted trailing hash comment preceded by whitespace is dropped, a leading UTF-8 BOM is ignored, and a line without an equals sign or with an empty name is now an error naming the file and line number, never the line content, instead of being skipped silently. Inline env still overrides file values. Covered by table-driven tests in internal/config/envfile_test.go including CRLF files and a sentinel test proving parse errors never echo a credential, mutation-checked by the reviewer. Docs: a format table in docs/configuration.qmd and an Unreleased changelog entry with an upgrade note, since existing files with trailing comments or quotes change meaning. Follow-up not in this PR: wraptool doctor still only checks that env files exist and have tight permissions, it does not parse them. 🤖 Generated with Claude Code

env_files were parsed literally, so SONARQUBE_TOKEN with surrounding double quotes reached the upstream MCP server with the quotes included and failed auth with Not authorized, which cost an hour of debugging today. resolveEnv now follows the dotenv convention: an optional leading export prefix is stripped, matching single or double quotes are removed from values, inside double quotes only the three escapes backslash-quote, backslash-backslash and backslash-n are processed while single quotes stay fully literal, an unquoted trailing hash comment preceded by whitespace is dropped, a leading UTF-8 BOM is ignored, and a line without an equals sign or with an empty name is now an error naming the file and line number, never the line content, instead of being skipped silently. Inline env still overrides file values. Covered by table-driven tests in internal/config/envfile_test.go including CRLF files and a sentinel test proving parse errors never echo a credential, mutation-checked by the reviewer. Docs: a format table in docs/configuration.qmd and an Unreleased changelog entry with an upgrade note, since existing files with trailing comments or quotes change meaning. Follow-up not in this PR: wraptool doctor still only checks that env files exist and have tight permissions, it does not parse them. 🤖 Generated with Claude Code
env_files were split on the first "=" with the raw value kept, so
TOKEN="abc" reached the tool with literal quotes (failing auth) and
"export KEY=v" produced a variable named "export KEY". Strip matching
quotes, accept an export prefix, drop an unquoted " # comment", and make
a line without "=" an error naming file and line instead of skipping it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The parse errors echoed the offending line, which reaches the agent
unscrubbed and may be a secret. Report file and line number only. Also
ignore a leading UTF-8 BOM, pin CRLF, export-prefix, single-quote and
quoted-then-garbage behavior with tests, and make the resolveEnv doc
comment, user docs table and changelog match the code.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
docs(changelog): name the mcp_servers failure mode for env_files parse errors
All checks were successful
Lint / lint (pull_request) Successful in 31m32s
Lint / sonarqube (pull_request) Has been skipped
c8e25bc7b1
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
pti merged commit 4184df0d8c into main 2026-10-19 15:49:46 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pti/wraptool!64
No description provided.