From 00ec796c7a685d455f5a1e9622b4af5b79a78e15 Mon Sep 17 00:00:00 2001 From: Toes | Robin Ury <1146921+binury@users.noreply.github.com> Date: Thu, 20 Aug 2026 16:38:04 -0400 Subject: [PATCH] Refactor: chat sanitization into NetworkChat proc --- network/network_chat_protocol.gd | 4 ++-- ui/chat_ui.gd | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/network/network_chat_protocol.gd b/network/network_chat_protocol.gd index ef7294d..6538295 100644 --- a/network/network_chat_protocol.gd +++ b/network/network_chat_protocol.gd @@ -15,8 +15,8 @@ enum Kind { PLAYER, SYSTEM } static func sanitize_body(value: Variant) -> String: if typeof(value) != TYPE_STRING: return "" - var result: String = str(value).replace("\r", " ").replace("\n", " ") - result = result.replace("\t", " ").strip_edges() + var strippable_whitespace = RegEx.create_from_string("^[\\s\\p{Z}\\p{Cf}\\x{2800}]+|[\\s\\p{Z}\\p{Cf}\\x{2800}]+$") + var result := strippable_whitespace.sub(value, "") if result.is_empty() or result.length() > MAX_VISIBLE_CHARACTERS: return "" if result.to_utf8_buffer().size() > MAX_UTF8_BYTES: diff --git a/ui/chat_ui.gd b/ui/chat_ui.gd index b157d70..0b26ffb 100644 --- a/ui/chat_ui.gd +++ b/ui/chat_ui.gd @@ -893,15 +893,14 @@ func _on_entry_text_submitted(_value: String) -> void: func _send() -> void: if _send_pending: return - var strippable_spaces := RegEx.create_from_string("(^\\s+|\\s+$)") - var body := strippable_spaces.sub(_entry.text, "", true) + var body := NetworkChatProtocol.sanitize_body(_entry.text) if body.is_empty(): close_chat() return if _handle_editor_world_command(body): return _send_pending = true - _pending_send_body = NetworkChatProtocol.sanitize_body(body) + _pending_send_body = body _entry.editable = false if not _service.send_local_message( body,