Skip to content

fix(config): substitute_env_vars skips TOML comments and preserves UTF-8 (closes #324)#343

Merged
obchain merged 1 commit intomainfrom
fix/324-env-var-skip-comments
Apr 26, 2026
Merged

fix(config): substitute_env_vars skips TOML comments and preserves UTF-8 (closes #324)#343
obchain merged 1 commit intomainfrom
fix/324-env-var-skip-comments

Conversation

@obchain
Copy link
Copy Markdown
Owner

@obchain obchain commented Apr 26, 2026

Summary

  • Replace linear find(\"\${\") scan with a TOML-comment-aware char walker.
  • \${VAR} inside #-prefixed comment lines pass through verbatim.
  • \${VAR} inside basic/literal/multi-line strings still substitutes (load-bearing).
  • A # inside a string is no longer mistaken for a comment-starter.
  • Walker iterates char_indices() (not raw bytes), preserves UTF-8 round-trip.

Why

A commented documentation example referencing an env var would force operators to export that var just to load the file. Closes #324.

Test plan

  • 11 new cases in env_substitution_tests (commented placeholder, # in URL string, UTF-8 round-trip, escaped quote, multi-line string, default fallback, live-line still errors, etc.)
  • cargo test --workspace --lib 56/56 + integration tests green
  • Existing signer_key = "\${CHARON_SIGNER_KEY}" substitution path unchanged

…F-8 (closes #324)

The substitution helper used to scan the raw TOML text linearly for
\${VAR} tokens, including text inside `#`-prefixed comment lines.
A documentation example like

    # auth_token = "\${CHARON_METRICS_AUTH_TOKEN}"

would force every operator to export `CHARON_METRICS_AUTH_TOKEN`
just to load the file, defeating the purpose of the comment showing
it as optional. Onboarding friction every fresh checkout.

Replace the linear scan with a TOML-comment-aware walker that
tracks string and comment state. `${VAR}` inside a comment passes
through verbatim; `${VAR}` inside a string still substitutes (the
load-bearing case for `signer_key = "\${CHARON_SIGNER_KEY}"`).
A `#` inside a string (URL fragment, hash-prefixed identifier) is
no longer mistaken for a comment-starter.

Walker iterates `char_indices()` rather than raw bytes so non-ASCII
content (UTF-8 strings, IRIs, operator-supplied labels) round-trips
unmodified — a previous draft used `bytes[i] as char` which mojibaked
two-byte sequences into four-byte garbage.

Tests: 11 new cases in `env_substitution_tests` covering commented
examples, default-form fallback, `#` inside basic and literal strings,
multi-line strings, escaped quote handling, UTF-8 round-trip, and
comment text byte-for-byte preservation (so TOML parser line
numbers stay aligned).
@obchain obchain force-pushed the fix/324-env-var-skip-comments branch from 65fab04 to fc873d8 Compare April 26, 2026 11:00
@obchain obchain merged commit a5c30ec into main Apr 26, 2026
1 check 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.

config: env-var ${VAR} substitution scans commented TOML lines, requires unused vars to be set

1 participant