1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-19 14:31:59 +00:00

Fix invalid DAP responses when content had non-ASCII content

This commit is contained in:
Ricardo Subtil
2025-04-02 19:20:13 +01:00
parent c7ea8614d7
commit 094ded8009
2 changed files with 9 additions and 12 deletions

View File

@@ -116,12 +116,12 @@ Error DAPeer::send_data() {
if (!data.has("seq")) { if (!data.has("seq")) {
data["seq"] = ++seq; data["seq"] = ++seq;
} }
String formatted_data = format_output(data); const Vector<uint8_t> &formatted_data = format_output(data);
int data_sent = 0; int data_sent = 0;
while (data_sent < formatted_data.length()) { while (data_sent < formatted_data.size()) {
int curr_sent = 0; 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) { if (err != OK) {
return err; return err;
} }
@@ -132,15 +132,12 @@ Error DAPeer::send_data() {
return OK; return OK;
} }
String DAPeer::format_output(const Dictionary &p_params) const { Vector<uint8_t> DAPeer::format_output(const Dictionary &p_params) const {
String response = Variant(p_params).to_json_string(); const Vector<uint8_t> &content = Variant(p_params).to_json_string().to_utf8_buffer();
String header = "Content-Length: "; Vector<uint8_t> response = vformat("Content-Length: %d\r\n\r\n", content.size()).to_utf8_buffer();
CharString charstr = response.utf8();
size_t len = charstr.length();
header += itos(len);
header += "\r\n\r\n";
return header + response; response.append_array(content);
return response;
} }
Error DebugAdapterProtocol::on_client_connected() { Error DebugAdapterProtocol::on_client_connected() {

View File

@@ -67,7 +67,7 @@ struct DAPeer : RefCounted {
Error handle_data(); Error handle_data();
Error send_data(); Error send_data();
String format_output(const Dictionary &p_params) const; Vector<uint8_t> format_output(const Dictionary &p_params) const;
}; };
class DebugAdapterProtocol : public Object { class DebugAdapterProtocol : public Object {