Skip to content

Commit 52016f8

Browse files
src: terminate correctly double-quote in env variable
1 parent 32ce183 commit 52016f8

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

src/node_dotenv.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void Dotenv::ParseLine(const std::string_view line) {
142142
auto quote_character = value[quotation_index];
143143
value.erase(0, 1);
144144

145-
auto end_quotation_index = value.find_last_of(quote_character);
145+
auto end_quotation_index = value.find(quote_character);
146146

147147
// We couldn't find the closing quotation character. Terminate.
148148
if (end_quotation_index == std::string::npos) {

test/fixtures/dotenv/valid.env

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ RETAIN_INNER_QUOTES_AS_BACKTICKS=`{"foo": "bar's"}`
3333
TRIM_SPACE_FROM_UNQUOTED= some spaced out string
3434
EMAIL=therealnerdybeast@example.tld
3535
SPACED_KEY = parsed
36+
EDGE_CASE_INLINE_COMMENTS="VALUE1" # or "VALUE2" or "VALUE3"

test/parallel/test-dotenv.js

+2
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ assert.strictEqual(process.env.TRIM_SPACE_FROM_UNQUOTED, 'some spaced out string
6868
assert.strictEqual(process.env.EMAIL, 'therealnerdybeast@example.tld');
6969
// Parses keys and values surrounded by spaces
7070
assert.strictEqual(process.env.SPACED_KEY, 'parsed');
71+
// Parse inline comments correctly when multiple quotes
72+
assert.strictEqual(process.env.EDGE_CASE_INLINE_COMMENTS, 'VALUE1');

0 commit comments

Comments
 (0)