fix(cli): strip inline comments when parsing .env values - #10101
Merged
diegosouzapw merged 1 commit intoAug 13, 2026
Merged
diegosouzapw merged 1 commit into
diegosouzapw merged 1 commit into
Conversation
loadEnvFile() took everything after the first '=', so 'KEY=value # note' stored the comment text as part of the value. The shipped .env/.env.example do exactly that for QUOTA_STORE_DRIVER, so every install ran with QUOTA_STORE_DRIVER='sqlite # sqlite | redis'. Consumers compare with '===' (storeFactory.ts), so a user following the annotation in .env.example and writing 'QUOTA_STORE_DRIVER=redis # ...' got driver !== 'redis', fell through to SQLite, and saw no warning — the existing 'no Redis URL configured' warning is inside the redis branch and never fires. parseEnvValue() adopts dotenv semantics: quoted values verbatim (a '#' inside quotes is data), unquoted values cut at the first whitespace-preceded '#', so 'pass#word' survives. .env.example moves the annotation to its own line. Closes #10100
This was referenced Aug 20, 2026
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
…w#10101) loadEnvFile() took everything after the first '=', so 'KEY=value # note' stored the comment text as part of the value. The shipped .env/.env.example do exactly that for QUOTA_STORE_DRIVER, so every install ran with QUOTA_STORE_DRIVER='sqlite # sqlite | redis'. Consumers compare with '===' (storeFactory.ts), so a user following the annotation in .env.example and writing 'QUOTA_STORE_DRIVER=redis # ...' got driver !== 'redis', fell through to SQLite, and saw no warning — the existing 'no Redis URL configured' warning is inside the redis branch and never fires. parseEnvValue() adopts dotenv semantics: quoted values verbatim (a '#' inside quotes is data), unquoted values cut at the first whitespace-preceded '#', so 'pass#word' survives. .env.example moves the annotation to its own line. Closes diegosouzapw#10100
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.
Closes #10100.
loadEnvFile()takes everything after the first=, soKEY=value # notestores the comment text as part of the value. The shipped.env/.env.exampledo exactly that, so every install runs with:Why it matters beyond cosmetics
storeFactory.tscompares exactly:A user who follows the annotation in your own
.env.exampleand writesQUOTA_STORE_DRIVER=redis # sqlite | redisgetsdriver !== "redis", falls through to SQLite, and sees no warning — the existingQUOTA_STORE_DRIVER=redis but no Redis URL configuredwarning lives inside the redis branch, so it never fires. Their Redis quota store just never engages. The same trap applies to any variable annotated inline, which the example file encourages.Change
parseEnvValue()with dotenv-compatible semantics: quoted values verbatim (a#inside quotes is data), unquoted values cut at the first whitespace-preceded#— sopass#wordandhttps://host/page#fragsurvive..env.examplemoves the annotation to its own line.Tests
New
tests/unit/cli-env-inline-comment-10100.test.ts(5 cases): inline comments stripped,#without preceding whitespace preserved, quoted values verbatim incl. a trailing comment after the closing quote, plain values unchanged, plus a guard asserting.env.examplenever reintroduces an unquoted inline comment on any variable.