Skip to content

Commit 3875fa1

Browse files
zcbenzrichardlau
authored andcommitted
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: #51665 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
1 parent 5202995 commit 3875fa1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/node_dotenv.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ void Dotenv::ParseContent(const std::string_view content) {
116116
value.erase(0, value.find_first_not_of(" \t"));
117117

118118
// Remove trailing whitespaces
119-
value.erase(value.find_last_not_of(" \t") + 1);
120-
121-
const char maybeQuote = value.front();
119+
if (!value.empty()) {
120+
value.erase(value.find_last_not_of(" \t") + 1);
121+
}
122122

123-
if (maybeQuote == '"') {
123+
if (!value.empty() && value.front() == '"') {
124124
value = std::regex_replace(value, std::regex("\\\\n"), "\n");
125125
value = std::regex_replace(value, std::regex("\\\\r"), "\r");
126126
}

0 commit comments

Comments
 (0)