Skip to content

Commit

Permalink
src: check empty before accessing string
Browse files Browse the repository at this point in the history
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: #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>
  • Loading branch information
zcbenz authored and targos committed Feb 19, 2024
1 parent ba444a9 commit 2a46dc7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/node_dotenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

const char maybeQuote = value.front();
if (!value.empty()) {
value.erase(value.find_last_not_of(" \t") + 1);
}

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");
}
Expand Down

0 comments on commit 2a46dc7

Please sign in to comment.