From 81122938653748459cbd18594adb1eaddada0292 Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Sat, 20 Jan 2024 10:44:13 +0100 Subject: [PATCH] src: terminate correctly double-quote in env variable PR-URL: https://github.com/nodejs/node/pull/51510 Fixes: https://github.com/nodejs/node/issues/51508 Reviewed-By: Yagiz Nizipli Reviewed-By: Debadree Chatterjee Reviewed-By: Benjamin Gruenbaum --- src/node_dotenv.cc | 2 +- test/fixtures/dotenv/valid.env | 1 + test/parallel/test-dotenv.js | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) 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');