mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
src: check empty before accessing string
Fix an assertion when running dotnev tests with GN build: assertion !empty() failed: string::front(): string is empty which was caused by calling value.front() without verifying the value is not empty. PR-URL: https://github.com/nodejs/node/pull/51665 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
This commit is contained in:
@@ -116,11 +116,11 @@ void Dotenv::ParseContent(const std::string_view content) {
|
||||
value.erase(0, value.find_first_not_of(" \t"));
|
||||
|
||||
// Remove trailing whitespaces
|
||||
value.erase(value.find_last_not_of(" \t") + 1);
|
||||
if (!value.empty()) {
|
||||
value.erase(value.find_last_not_of(" \t") + 1);
|
||||
}
|
||||
|
||||
const char maybeQuote = value.front();
|
||||
|
||||
if (maybeQuote == '"') {
|
||||
if (!value.empty() && value.front() == '"') {
|
||||
value = std::regex_replace(value, std::regex("\\\\n"), "\n");
|
||||
value = std::regex_replace(value, std::regex("\\\\r"), "\r");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user