fix: safely handle whitespace and consecutive newlines (#1288)

This commit is contained in:
leejet 2026-02-19 20:54:42 +08:00 committed by GitHub
parent c5eb1e4137
commit c9cd49701a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -919,15 +919,21 @@ std::vector<std::string> token_split(const std::string& text) {
// `\s*[\r\n]+|\s+(?!\S)|\s+`
if (is_space(cp)) {
std::string token = codepoint_to_utf8(cp);
++i;
std::string token;
bool saw_new_line = false;
while (i < cps.size() && is_space(cps[i])) {
token += codepoint_to_utf8(cps[i]);
++i;
if (cps[i] == U'\r' || cps[i] == U'\n') {
break;
saw_new_line = true;
} else {
if (saw_new_line) {
break;
}
}
++i;
}
tokens.push_back(token);