Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/node_dotenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ void Dotenv::ParseContent(const std::string_view input) {
content.remove_prefix(equal_or_newline + 1);
key = trim_spaces(key);

// Only strip spaces and tabs here: trim_spaces() also strips '\n', which
// would turn the next line into the value of an empty `KEY= `.
content.remove_prefix(
std::min(content.find_first_not_of(" \t"), content.size()));

// If the value is not present (e.g. KEY=) set it to an empty string
if (content.empty() || content.front() == '\n') {
store_.insert_or_assign(std::string(key), "");
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-util-parse-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ assert.deepStrictEqual(util.parseEnv(''), { __proto__: null });
assert.deepStrictEqual(util.parseEnv('FOO=bar\nFOO=baz\n'),
{ __proto__: null, FOO: 'baz' });

// Whitespace after an empty value must not pull in the next line.
// Refs: https://github.com/nodejs/node/issues/67400
assert.deepStrictEqual(util.parseEnv('A= \nB=b\nC=\t\nD=d\nE= '),
{ __proto__: null, A: '', B: 'b', C: '', D: 'd', E: '' });

// Test for invalid input.
assert.throws(() => {
for (const value of [null, undefined, {}, []]) {
Expand Down
Loading