Skip to content

Enhance .env parsing for inline comments with leading whitespace#1029

Open
udithavithanage wants to merge 1 commit into
motdotla:masterfrom
udithavithanage:master
Open

Enhance .env parsing for inline comments with leading whitespace#1029
udithavithanage wants to merge 1 commit into
motdotla:masterfrom
udithavithanage:master

Conversation

@udithavithanage

Copy link
Copy Markdown

This pull request improves the parsing of inline comments in environment variable files, especially around handling the # character in values. The main change is to correctly distinguish between # as part of a value and # as the start of a comment, depending on whether it is preceded by whitespace. This is reflected in both the parser logic and expanded test coverage.

Parsing improvements

  • Updated the LINE regular expression in lib/main.js to treat # as the start of a comment only when it is preceded by whitespace.
  • This allows # to be included as part of an environment variable value when it is not preceded by whitespace.

Examples

Input Output
DB_PASS=test*&#secret123 test*&#secret123
DB_PASS=test #secret123 test
DB_PASS="test #secret123" test #secret123

Test coverage enhancements

  • Added new test cases in tests/.env, tests/.env.multiline, and corresponding assertions in tests/test-parse.js and tests/test-parse-multiline.js.
  • Added coverage for:
    • Inline comments following values.
    • # characters embedded in unquoted values.
    • # characters inside quoted values.
    • Cases where # is and is not preceded by whitespace.

These tests verify that comments are parsed correctly while preserving # characters that are intended to be part of the value.

Fixes: #1018

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.

Incomplete Parsing Caused by # Symbol in Configuration Content

1 participant