forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: support multi-line values for .env file
PR-URL: nodejs#51289 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Zeyu "Alex" Yang <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
- Loading branch information
1 parent
09df9d2
commit 6c2fd52
Showing
6 changed files
with
114 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ BACKTICKS_SPACED=` backticks ` | |
DOUBLE_QUOTES_INSIDE_BACKTICKS=`double "quotes" work inside backticks` | ||
SINGLE_QUOTES_INSIDE_BACKTICKS=`single 'quotes' work inside backticks` | ||
DOUBLE_AND_SINGLE_QUOTES_INSIDE_BACKTICKS=`double "quotes" and single 'quotes' work inside backticks` | ||
EXPAND_NEWLINES="expand\nnew\nlines" | ||
DONT_EXPAND_UNQUOTED=dontexpand\nnewlines | ||
DONT_EXPAND_SQUOTED='dontexpand\nnewlines' | ||
# COMMENTS=work | ||
INLINE_COMMENTS=inline comments # work #very #well | ||
INLINE_COMMENTS_SINGLE_QUOTES='inline comments outside of #singlequotes' # work | ||
|
@@ -34,3 +37,25 @@ TRIM_SPACE_FROM_UNQUOTED= some spaced out string | |
EMAIL=[email protected] | ||
SPACED_KEY = parsed | ||
EDGE_CASE_INLINE_COMMENTS="VALUE1" # or "VALUE2" or "VALUE3" | ||
|
||
MULTI_DOUBLE_QUOTED="THIS | ||
IS | ||
A | ||
MULTILINE | ||
STRING" | ||
|
||
MULTI_SINGLE_QUOTED='THIS | ||
IS | ||
A | ||
MULTILINE | ||
STRING' | ||
|
||
MULTI_BACKTICKED=`THIS | ||
IS | ||
A | ||
"MULTILINE'S" | ||
STRING` | ||
MULTI_NOT_VALID_QUOTE=" | ||
MULTI_NOT_VALID=THIS | ||
IS NOT MULTILINE | ||
export EXAMPLE = ignore export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,8 @@ assert.strictEqual(process.env.INLINE_COMMENTS_DOUBLE_QUOTES, 'inline comments o | |
assert.strictEqual(process.env.INLINE_COMMENTS_BACKTICKS, 'inline comments outside of #backticks'); | ||
// Treats # character as start of comment | ||
assert.strictEqual(process.env.INLINE_COMMENTS_SPACE, 'inline comments start with a'); | ||
// ignore comment | ||
assert.strictEqual(process.env.COMMENTS, undefined); | ||
// Respects equals signs in values | ||
assert.strictEqual(process.env.EQUAL_SIGNS, 'equals=='); | ||
// Retains inner quotes | ||
|
@@ -70,3 +72,15 @@ assert.strictEqual(process.env.EMAIL, '[email protected]'); | |
assert.strictEqual(process.env.SPACED_KEY, 'parsed'); | ||
// Parse inline comments correctly when multiple quotes | ||
assert.strictEqual(process.env.EDGE_CASE_INLINE_COMMENTS, 'VALUE1'); | ||
// Test multi-line values with line breaks | ||
assert.strictEqual(process.env.MULTI_DOUBLE_QUOTED, 'THIS\nIS\nA\nMULTILINE\nSTRING'); | ||
assert.strictEqual(process.env.MULTI_SINGLE_QUOTED, 'THIS\nIS\nA\nMULTILINE\nSTRING'); | ||
assert.strictEqual(process.env.MULTI_BACKTICKED, 'THIS\nIS\nA\n"MULTILINE\'S"\nSTRING'); | ||
assert.strictEqual(process.env.MULTI_NOT_VALID_QUOTE, '"'); | ||
assert.strictEqual(process.env.MULTI_NOT_VALID, 'THIS'); | ||
// Test that \n is expanded to a newline in double-quoted string | ||
assert.strictEqual(process.env.EXPAND_NEWLINES, 'expand\nnew\nlines'); | ||
assert.strictEqual(process.env.DONT_EXPAND_UNQUOTED, 'dontexpand\\nnewlines'); | ||
assert.strictEqual(process.env.DONT_EXPAND_SQUOTED, 'dontexpand\\nnewlines'); | ||
// Ignore export before key | ||
assert.strictEqual(process.env.EXAMPLE, 'ignore export'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,23 +17,33 @@ const fs = require('node:fs'); | |
BACKTICKS_INSIDE_SINGLE: '`backticks` work inside single quotes', | ||
BACKTICKS_SPACED: ' backticks ', | ||
BASIC: 'basic', | ||
DOUBLE_AND_SINGLE_QUOTES_INSIDE_BACKTICKS: 'double "quotes" and single \'quotes\' work inside backticks', | ||
DONT_EXPAND_SQUOTED: 'dontexpand\\nnewlines', | ||
DONT_EXPAND_UNQUOTED: 'dontexpand\\nnewlines', | ||
DOUBLE_AND_SINGLE_QUOTES_INSIDE_BACKTICKS: "double \"quotes\" and single 'quotes' work inside backticks", | ||
DOUBLE_QUOTES: 'double_quotes', | ||
DOUBLE_QUOTES_INSIDE_BACKTICKS: 'double "quotes" work inside backticks', | ||
DOUBLE_QUOTES_INSIDE_SINGLE: 'double "quotes" work inside single quotes', | ||
DOUBLE_QUOTES_SPACED: ' double quotes ', | ||
DOUBLE_QUOTES_WITH_NO_SPACE_BRACKET: '{ port: $MONGOLAB_PORT}', | ||
EDGE_CASE_INLINE_COMMENTS: 'VALUE1', | ||
EMAIL: '[email protected]', | ||
EMPTY: '', | ||
EMPTY_BACKTICKS: '', | ||
EMPTY_DOUBLE_QUOTES: '', | ||
EMPTY_SINGLE_QUOTES: '', | ||
EQUAL_SIGNS: 'equals==', | ||
EXAMPLE: 'ignore export', | ||
EXPAND_NEWLINES: 'expand\nnew\nlines', | ||
INLINE_COMMENTS: 'inline comments', | ||
INLINE_COMMENTS_BACKTICKS: 'inline comments outside of #backticks', | ||
INLINE_COMMENTS_DOUBLE_QUOTES: 'inline comments outside of #doublequotes', | ||
INLINE_COMMENTS_SINGLE_QUOTES: 'inline comments outside of #singlequotes', | ||
INLINE_COMMENTS_SPACE: 'inline comments start with a', | ||
MULTI_BACKTICKED: 'THIS\nIS\nA\n"MULTILINE\'S"\nSTRING', | ||
MULTI_DOUBLE_QUOTED: 'THIS\nIS\nA\nMULTILINE\nSTRING', | ||
MULTI_NOT_VALID: 'THIS', | ||
MULTI_NOT_VALID_QUOTE: '"', | ||
MULTI_SINGLE_QUOTED: 'THIS\nIS\nA\nMULTILINE\nSTRING', | ||
RETAIN_INNER_QUOTES: '{"foo": "bar"}', | ||
RETAIN_INNER_QUOTES_AS_BACKTICKS: '{"foo": "bar\'s"}', | ||
RETAIN_INNER_QUOTES_AS_STRING: '{"foo": "bar"}', | ||
|
@@ -42,7 +52,7 @@ const fs = require('node:fs'); | |
SINGLE_QUOTES_INSIDE_DOUBLE: "single 'quotes' work inside double quotes", | ||
SINGLE_QUOTES_SPACED: ' single quotes ', | ||
SPACED_KEY: 'parsed', | ||
TRIM_SPACE_FROM_UNQUOTED: 'some spaced out string' | ||
TRIM_SPACE_FROM_UNQUOTED: 'some spaced out string', | ||
}); | ||
} | ||
|
||
|