Skip to content

fix: do not let an empty colon value consume the next line - #1091

Open
saruk-vedant wants to merge 1 commit into
motdotla:masterfrom
saruk-vedant:dotenv-1090-colon-empty-value
Open

saruk-vedant wants to merge 1 commit into
motdotla:masterfrom
saruk-vedant:dotenv-1090-colon-empty-value

Conversation

@saruk-vedant

Copy link
Copy Markdown

Summary

A key written with a colon and nothing after it eats the next line, so the variable below it disappears. For example, A:\nB=2 parsed as { A: 'B=2' } instead of { A: '', B: '2' }, in both the classic parser and parseFast.

In lib/main.js, the classic LINE regex separator changed from :\s+? (which could swallow the line break) to :(?:[^\S\r\n]+?|(?=\r|\n|$)), so after a colon only same-line whitespace is consumed, and a line ending leaves an empty value while still letting a quoted value on the next line match. In parseFast, the colon branch now advances past only the colon when the next character is a line ending or the colon is the last character, instead of skipping the newline.

Two stale expectations in tests/test-parse-fast.js (from commit 048dd48, which encoded the old A:\nfoo gives { A: 'foo' } behaviour) were updated, and a new test an empty colon value does not consume the next line with 14 cases checked against both parsers was added.

How to test

  • Full npm test (build, lint, type check, all tap tests): 1456 total, 1455 pass, 1 skip, 0 fail.
  • Parse-focused run (tests/test-parse.js, tests/test-parse-fast.js, tests/test-parse-multiline.js): 1085 assertions, all pass.
  • standard lint on the two changed files: clean.
  • 14 adversarial cases in both parsers, all pass: the reported case, colon-space-newline, CRLF, colon at end of file, normal colon and equals values, multiple consecutive empty-colon lines, empty-colon followed by a comment, quoted value on the next line, URL:http://x still giving {}, non-breaking space after the colon, and a value with a trailing comment.

Fixes #1090

Changelog

This repo generates CHANGELOG.md at release time via standard-version, and recent merged fix PRs add no changelog entry, so no changelog fragment is included.

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.

KEY: with an empty value takes the next line as its value

1 participant