Skip to content

Commit aca49fc

Browse files
authored
src: fix env-file flag to ignore spaces before quotes
Fix to ignore spaces between '=' and quoted string in env file Fixes: #53461 Signed-off-by: Mohit Malhotra <dev.mohitmalhotra@gmail.com> PR-URL: #53786 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 05ca035 commit aca49fc

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

src/node_dotenv.cc

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ void Dotenv::ParseContent(const std::string_view input) {
129129
key = content.substr(0, equal);
130130
content.remove_prefix(equal + 1);
131131
key = trim_spaces(key);
132+
content = trim_spaces(content);
132133

133134
if (key.empty()) {
134135
break;

test/fixtures/dotenv/valid.env

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ RETAIN_INNER_QUOTES={"foo": "bar"}
3838
RETAIN_INNER_QUOTES_AS_STRING='{"foo": "bar"}'
3939
RETAIN_INNER_QUOTES_AS_BACKTICKS=`{"foo": "bar's"}`
4040
TRIM_SPACE_FROM_UNQUOTED= some spaced out string
41+
SPACE_BEFORE_DOUBLE_QUOTES= "space before double quotes"
4142
EMAIL=therealnerdybeast@example.tld
4243
SPACED_KEY = parsed
4344
EDGE_CASE_INLINE_COMMENTS="VALUE1" # or "VALUE2" or "VALUE3"

test/parallel/test-dotenv.js

+2
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,5 @@ assert.strictEqual(process.env.DONT_EXPAND_UNQUOTED, 'dontexpand\\nnewlines');
8080
assert.strictEqual(process.env.DONT_EXPAND_SQUOTED, 'dontexpand\\nnewlines');
8181
// Ignore export before key
8282
assert.strictEqual(process.env.EXPORT_EXAMPLE, 'ignore export');
83+
// Ignore spaces before double quotes to avoid quoted strings as value
84+
assert.strictEqual(process.env.SPACE_BEFORE_DOUBLE_QUOTES, 'space before double quotes');

0 commit comments

Comments
 (0)