From 094ded8009bb818e7fa5c311ff5cc83382ccf3ca Mon Sep 17 00:00:00 2001 From: Ricardo Subtil Date: Wed, 2 Apr 2025 19:20:13 +0100 Subject: [PATCH] Fix invalid DAP responses when content had non-ASCII content --- .../debug_adapter/debug_adapter_protocol.cpp | 19 ++++++++----------- .../debug_adapter/debug_adapter_protocol.h | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp index 35d841849c9..49249d85604 100644 --- a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp @@ -116,12 +116,12 @@ Error DAPeer::send_data() { if (!data.has("seq")) { data["seq"] = ++seq; } - String formatted_data = format_output(data); + const Vector &formatted_data = format_output(data); int data_sent = 0; - while (data_sent < formatted_data.length()) { + while (data_sent < formatted_data.size()) { int curr_sent = 0; - Error err = connection->put_partial_data((const uint8_t *)formatted_data.utf8().get_data(), formatted_data.size() - data_sent - 1, curr_sent); + Error err = connection->put_partial_data(formatted_data.ptr() + data_sent, formatted_data.size() - data_sent, curr_sent); if (err != OK) { return err; } @@ -132,15 +132,12 @@ Error DAPeer::send_data() { return OK; } -String DAPeer::format_output(const Dictionary &p_params) const { - String response = Variant(p_params).to_json_string(); - String header = "Content-Length: "; - CharString charstr = response.utf8(); - size_t len = charstr.length(); - header += itos(len); - header += "\r\n\r\n"; +Vector DAPeer::format_output(const Dictionary &p_params) const { + const Vector &content = Variant(p_params).to_json_string().to_utf8_buffer(); + Vector response = vformat("Content-Length: %d\r\n\r\n", content.size()).to_utf8_buffer(); - return header + response; + response.append_array(content); + return response; } Error DebugAdapterProtocol::on_client_connected() { diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.h b/editor/debugger/debug_adapter/debug_adapter_protocol.h index 23d1bdb1544..9cd5741b19f 100644 --- a/editor/debugger/debug_adapter/debug_adapter_protocol.h +++ b/editor/debugger/debug_adapter/debug_adapter_protocol.h @@ -67,7 +67,7 @@ struct DAPeer : RefCounted { Error handle_data(); Error send_data(); - String format_output(const Dictionary &p_params) const; + Vector format_output(const Dictionary &p_params) const; }; class DebugAdapterProtocol : public Object {