Skip to content

Commit c7267a5

Browse files
committed
test: add test case
1 parent 12105d9 commit c7267a5

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

β€Žsrc/node_dotenv.ccβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,13 @@ void Dotenv::ParseContent(const std::string_view input) {
147147
if (equal == std::string_view::npos) {
148148
auto newline = content.find('\n');
149149
if (newline != std::string_view::npos) {
150+
// If we used `newline` only,
151+
// the '\n' might remain and cause an empty-line parse
150152
content.remove_prefix(newline + 1);
151153
} else {
152154
content = {};
153155
}
156+
// No valid data here, skip to next line
154157
continue;
155158
}
156159

@@ -234,10 +237,12 @@ void Dotenv::ParseContent(const std::string_view input) {
234237
// since there could be newline characters inside the value.
235238
auto newline = content.find('\n', closing_quote + 1);
236239
if (newline != std::string_view::npos) {
240+
// Use +1 to discard the '\n' itself => next line
237241
content.remove_prefix(newline + 1);
238242
} else {
239243
content = {};
240244
}
245+
// No valid data here, skip to next line
241246
continue;
242247
}
243248
} else {

β€Žtest/fixtures/dotenv/valid.envβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ BASIC=basic
77
# previous line intentionally left blank
88
AFTER_LINE=after_line
99
A="B=C"
10+
B=C=D
1011
EMPTY=
1112
EMPTY_SINGLE_QUOTES=''
1213
EMPTY_DOUBLE_QUOTES=""

β€Žtest/parallel/test-dotenv.jsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ assert.strictEqual(process.env.EXPORT_EXAMPLE, 'ignore export');
8383
// Ignore spaces before double quotes to avoid quoted strings as value
8484
assert.strictEqual(process.env.SPACE_BEFORE_DOUBLE_QUOTES, 'space before double quotes');
8585
assert.strictEqual(process.env.A, 'B=C');
86+
assert.strictEqual(process.env.B, 'C=D');

β€Žtest/parallel/test-util-parse-env.jsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const fs = require('node:fs');
1212

1313
assert.deepStrictEqual(util.parseEnv(validContent), {
1414
A: 'B=C',
15+
B: 'C=D',
1516
AFTER_LINE: 'after_line',
1617
BACKTICKS: 'backticks',
1718
BACKTICKS_INSIDE_DOUBLE: '`backticks` work inside double quotes',

0 commit comments

Comments
Β (0)