mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
src: fix env-file flag to ignore spaces before quotes
Fix to ignore spaces between '=' and quoted string in env file Fixes: https://github.com/nodejs/node/issues/53461 Signed-off-by: Mohit Malhotra <dev.mohitmalhotra@gmail.com> PR-URL: https://github.com/nodejs/node/pull/53786 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
parent
05ca03569e
commit
aca49fc7d1
@ -129,6 +129,7 @@ void Dotenv::ParseContent(const std::string_view input) {
|
|||||||
key = content.substr(0, equal);
|
key = content.substr(0, equal);
|
||||||
content.remove_prefix(equal + 1);
|
content.remove_prefix(equal + 1);
|
||||||
key = trim_spaces(key);
|
key = trim_spaces(key);
|
||||||
|
content = trim_spaces(content);
|
||||||
|
|
||||||
if (key.empty()) {
|
if (key.empty()) {
|
||||||
break;
|
break;
|
||||||
|
1
test/fixtures/dotenv/valid.env
vendored
1
test/fixtures/dotenv/valid.env
vendored
@ -38,6 +38,7 @@ RETAIN_INNER_QUOTES={"foo": "bar"}
|
|||||||
RETAIN_INNER_QUOTES_AS_STRING='{"foo": "bar"}'
|
RETAIN_INNER_QUOTES_AS_STRING='{"foo": "bar"}'
|
||||||
RETAIN_INNER_QUOTES_AS_BACKTICKS=`{"foo": "bar's"}`
|
RETAIN_INNER_QUOTES_AS_BACKTICKS=`{"foo": "bar's"}`
|
||||||
TRIM_SPACE_FROM_UNQUOTED= some spaced out string
|
TRIM_SPACE_FROM_UNQUOTED= some spaced out string
|
||||||
|
SPACE_BEFORE_DOUBLE_QUOTES= "space before double quotes"
|
||||||
EMAIL=therealnerdybeast@example.tld
|
EMAIL=therealnerdybeast@example.tld
|
||||||
SPACED_KEY = parsed
|
SPACED_KEY = parsed
|
||||||
EDGE_CASE_INLINE_COMMENTS="VALUE1" # or "VALUE2" or "VALUE3"
|
EDGE_CASE_INLINE_COMMENTS="VALUE1" # or "VALUE2" or "VALUE3"
|
||||||
|
@ -80,3 +80,5 @@ assert.strictEqual(process.env.DONT_EXPAND_UNQUOTED, 'dontexpand\\nnewlines');
|
|||||||
assert.strictEqual(process.env.DONT_EXPAND_SQUOTED, 'dontexpand\\nnewlines');
|
assert.strictEqual(process.env.DONT_EXPAND_SQUOTED, 'dontexpand\\nnewlines');
|
||||||
// Ignore export before key
|
// Ignore export before key
|
||||||
assert.strictEqual(process.env.EXPORT_EXAMPLE, 'ignore export');
|
assert.strictEqual(process.env.EXPORT_EXAMPLE, 'ignore export');
|
||||||
|
// Ignore spaces before double quotes to avoid quoted strings as value
|
||||||
|
assert.strictEqual(process.env.SPACE_BEFORE_DOUBLE_QUOTES, 'space before double quotes');
|
||||||
|
Loading…
Reference in New Issue
Block a user