diff --git a/src/node_dotenv.cc b/src/node_dotenv.cc index 992633c50b9a14..7376a97636f1b1 100644 --- a/src/node_dotenv.cc +++ b/src/node_dotenv.cc @@ -142,7 +142,7 @@ void Dotenv::ParseLine(const std::string_view line) { auto quote_character = value[quotation_index]; value.erase(0, 1); - auto end_quotation_index = value.find_last_of(quote_character); + auto end_quotation_index = value.find(quote_character); // We couldn't find the closing quotation character. Terminate. if (end_quotation_index == std::string::npos) { diff --git a/test/fixtures/dotenv/valid.env b/test/fixtures/dotenv/valid.env index c1c12b112b965b..980d3621b0c4df 100644 --- a/test/fixtures/dotenv/valid.env +++ b/test/fixtures/dotenv/valid.env @@ -33,3 +33,4 @@ RETAIN_INNER_QUOTES_AS_BACKTICKS=`{"foo": "bar's"}` TRIM_SPACE_FROM_UNQUOTED= some spaced out string EMAIL=therealnerdybeast@example.tld SPACED_KEY = parsed +EDGE_CASE_INLINE_COMMENTS="VALUE1" # or "VALUE2" or "VALUE3" diff --git a/test/parallel/test-dotenv.js b/test/parallel/test-dotenv.js index 9c374c8735910d..efc5a164b39334 100644 --- a/test/parallel/test-dotenv.js +++ b/test/parallel/test-dotenv.js @@ -68,3 +68,5 @@ assert.strictEqual(process.env.TRIM_SPACE_FROM_UNQUOTED, 'some spaced out string assert.strictEqual(process.env.EMAIL, 'therealnerdybeast@example.tld'); // Parses keys and values surrounded by spaces assert.strictEqual(process.env.SPACED_KEY, 'parsed'); +// Parse inline comments correctly when multiple quotes +assert.strictEqual(process.env.EDGE_CASE_INLINE_COMMENTS, 'VALUE1');