Conversation
…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).
65fab04 to
fc873d8
Compare
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.
Summary
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).#inside a string is no longer mistaken for a comment-starter.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
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 --lib56/56 + integration tests greensigner_key = "\${CHARON_SIGNER_KEY}"substitution path unchanged