Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
util: fix parseEnv incorrectly splitting multiple ‘=‘ in value#57421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
be4ee4db0680d88a094b712105d9af806521ac38adFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -145,7 +145,16 @@ void Dotenv::ParseContent(const std::string_view input) { | ||
| // If there is no equal character, then ignore everything | ||
| auto equal = content.find('='); | ||
| if (equal == std::string_view::npos) { | ||
| break; | ||
| auto newline = content.find('\n'); | ||
| if (newline != std::string_view::npos) { | ||
| // If we used `newline` only, | ||
| // the '\n' might remain and cause an empty-line parse | ||
| content.remove_prefix(newline + 1); | ||
| } else { | ||
| content = {}; | ||
| } | ||
| // No valid data here, skip to next line | ||
| continue; | ||
| } | ||
| key = content.substr(0, equal); | ||
| @@ -195,7 +204,9 @@ void Dotenv::ParseContent(const std::string_view input) { | ||
| store_.insert_or_assign(std::string(key), multi_line_value); | ||
| auto newline = content.find('\n', closing_quote + 1); | ||
| if (newline != std::string_view::npos) { | ||
| content.remove_prefix(newline); | ||
| content.remove_prefix(newline + 1); | ||
| } else { | ||
| content = {}; | ||
| } | ||
| continue; | ||
| } | ||
| @@ -216,7 +227,7 @@ void Dotenv::ParseContent(const std::string_view input) { | ||
| if (newline != std::string_view::npos) { | ||
| value = content.substr(0, newline); | ||
| store_.insert_or_assign(std::string(key), value); | ||
| content.remove_prefix(newline); | ||
| content.remove_prefix(newline + 1); | ||
rayark1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } else { | ||
| // Example: KEY="value" | ||
| @@ -226,8 +237,13 @@ void Dotenv::ParseContent(const std::string_view input) { | ||
| // since there could be newline characters inside the value. | ||
| auto newline = content.find('\n', closing_quote + 1); | ||
| if (newline != std::string_view::npos) { | ||
| content.remove_prefix(newline); | ||
| // Use +1 to discard the '\n' itself => next line | ||
| content.remove_prefix(newline + 1); | ||
| } else { | ||
| content = {}; | ||
| } | ||
| // No valid data here, skip to next line | ||
| continue; | ||
anonrig marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } else { | ||
| // Regular key value pair. | ||
| @@ -243,15 +259,21 @@ void Dotenv::ParseContent(const std::string_view input) { | ||
| if (hash_character != std::string_view::npos) { | ||
| value = content.substr(0, hash_character); | ||
| } | ||
| content.remove_prefix(newline); | ||
| store_.insert_or_assign(std::string(key), trim_spaces(value)); | ||
| content.remove_prefix(newline + 1); | ||
| } else { | ||
| // In case the last line is a single key/value pair | ||
| // Example: KEY=VALUE (without a newline at the EOF) | ||
| value = content.substr(0); | ||
| value = content; | ||
| auto hash_char = value.find('#'); | ||
| if (hash_char != std::string_view::npos) { | ||
| value = content.substr(0, hash_char); | ||
| } | ||
| store_.insert_or_assign(std::string(key), trim_spaces(value)); | ||
| content = {}; | ||
| } | ||
| value = trim_spaces(value); | ||
| store_.insert_or_assign(std::string(key), value); | ||
| store_.insert_or_assign(std::string(key), trim_spaces(value)); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -82,3 +82,5 @@ assert.strictEqual(process.env.DONT_EXPAND_SQUOTED, 'dontexpand\\nnewlines'); | ||
| assert.strictEqual(process.env.EXPORT_EXAMPLE, 'ignore export'); | ||
| // Ignore spaces before double quotes to avoid quoted strings as value | ||
| assert.strictEqual(process.env.SPACE_BEFORE_DOUBLE_QUOTES, 'space before double quotes'); | ||
| assert.strictEqual(process.env.A, 'B=C'); | ||
rayark1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| assert.strictEqual(process.env.B, 'C=D'); | ||
Uh oh!
There was an error while loading. Please reload this page.