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.
  • Loading branch information
zcbenz committed Feb 5, 2024
1 parent 9448c61 commit b208e65
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 b208e65

Please sign in to comment.