fix JSON array/object parser regression in JParser::parse_value

This commit is contained in:
Luxferre
2026-10-14 11:11:28 +03:00
parent 6e80a3e8fc
commit e57fbed5ba
2 changed files with 27 additions and 3 deletions
+3 -3
View File
@@ -225,7 +225,7 @@ bool parse_nonstream_response(std::string_view body, Message &out, Usage &usage)
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* llm.cpp — HTTP client (libcurl), headers, backoff, dispatch. */ /* llm.cpp — HTTP client (libcurl), headers, backoff, dispatch. */
/* -------------------------------------------------------------- */ /* ------------------------------------------------------------------ */
int http_get(Cfg &cfg, std::string_view url, std::string &body, long &code, int http_get(Cfg &cfg, std::string_view url, std::string &body, long &code,
std::string &errmsg); std::string &errmsg);
int llm(Cfg &cfg, Messages &msgs, bool use_tools, Message &out, Usage &usage, int llm(Cfg &cfg, Messages &msgs, bool use_tools, Message &out, Usage &usage,
@@ -239,8 +239,8 @@ std::string shell_with_workdir(std::string_view cmd, std::string_view workdir,
std::string read_file_or_dir(std::string_view path, int offset, int limit, std::string read_file_or_dir(std::string_view path, int offset, int limit,
int *style); int *style);
std::string write_file(std::string_view path, long line_offset, long byte_offset, std::string write_file(std::string_view path, long line_offset, long byte_offset,
long del_lines, long del_bytes, long del_lines, long del_bytes,
std::string_view content, int *err); std::string_view content, int *err);
std::string offload_tool_result(std::string_view res, int max_res, std::string offload_tool_result(std::string_view res, int max_res,
std::vector<std::string> &tmps); std::vector<std::string> &tmps);
void cleanup_temps(std::vector<std::string> &tmps); void cleanup_temps(std::vector<std::string> &tmps);
+24
View File
@@ -401,6 +401,30 @@ struct JParser {
return true; return true;
} }
if (c == '[') { if (c == '[') {
pos++;
skip_ws();
out = Json::array();
if (pos < src.size() && src[pos] == ']') {
pos++;
return true;
}
while (true) {
Json elem;
if (!parse_value(elem, depth + 1)) return false;
out.aval.push_back(std::move(elem));
skip_ws();
if (pos < src.size() && src[pos] == ',') {
pos++;
continue;
}
if (pos < src.size() && src[pos] == ']') {
pos++;
return true;
}
return false;
}
}
if (c == '{') {
pos++; pos++;
skip_ws(); skip_ws();
out = Json::object(); out = Json::object();