fix: Complete JSON escaping in fingerprint_mcp_args

Address coderabbitai review - implement full JSON escaping for SQL digest:
- Handle backslash (\) and double quote (")
- Handle control characters: newline (\n), carriage return (\r), tab (\t)
- Handle other control characters (U+0000 through U+001F) with \uXXXX escapes

This ensures digest_text in stats_mcp_query_digest is always valid JSON,
preventing parsing errors for consumers of this data.
pull/5312/head
Rene Cannao 4 months ago
parent f2536f01d2
commit 7b6966b9c2

@ -3049,12 +3049,20 @@ std::string Discovery_Schema::fingerprint_mcp_args(const nlohmann::json& argumen
// Escape the digest for JSON and add it to result
result += "\"";
if (digest) {
// Simple JSON escaping - escape backslashes and quotes
// Full JSON escaping - handle all control characters
for (const char* p = digest; *p; p++) {
if (*p == '\\' || *p == '"') {
result += '\\';
unsigned char c = (unsigned char)*p;
if (c == '\\') result += "\\\\";
else if (c == '"') result += "\\\"";
else if (c == '\n') result += "\\n";
else if (c == '\r') result += "\\r";
else if (c == '\t') result += "\\t";
else if (c < 0x20) {
char buf[8];
snprintf(buf, sizeof(buf), "\\u%04x", c);
result += buf;
}
result += *p;
else result += *p;
}
free(digest);
}

Loading…
Cancel
Save