Skip to content

Commit

Permalink
src: terminate correctly double-quote in env variable
Browse files Browse the repository at this point in the history
PR-URL: nodejs#51510
Fixes: nodejs#51508
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
marco-ippolito committed Jan 29, 2024
1 parent b3f7fd4 commit 8112293
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/node_dotenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/dotenv/valid.env
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions test/parallel/test-dotenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 8112293

Please sign in to comment.