forked from woofmeow/straywild
Refactor: chat sanitization into NetworkChat proc
This commit is contained in:
parent
0cba516b82
commit
237c1db5d1
2 changed files with 4 additions and 5 deletions
|
|
@ -15,8 +15,8 @@ enum Kind { PLAYER, SYSTEM }
|
||||||
static func sanitize_body(value: Variant) -> String:
|
static func sanitize_body(value: Variant) -> String:
|
||||||
if typeof(value) != TYPE_STRING:
|
if typeof(value) != TYPE_STRING:
|
||||||
return ""
|
return ""
|
||||||
var result: String = str(value).replace("\r", " ").replace("\n", " ")
|
var strippable_whitespace = RegEx.create_from_string("^[\\s\\p{Z}\\p{Cf}\\x{2800}]+|[\\s\\p{Z}\\p{Cf}\\x{2800}]+$")
|
||||||
result = result.replace("\t", " ").strip_edges()
|
var result := strippable_whitespace.sub(value, "")
|
||||||
if result.is_empty() or result.length() > MAX_VISIBLE_CHARACTERS:
|
if result.is_empty() or result.length() > MAX_VISIBLE_CHARACTERS:
|
||||||
return ""
|
return ""
|
||||||
if result.to_utf8_buffer().size() > MAX_UTF8_BYTES:
|
if result.to_utf8_buffer().size() > MAX_UTF8_BYTES:
|
||||||
|
|
|
||||||
|
|
@ -893,13 +893,12 @@ func _on_entry_text_submitted(_value: String) -> void:
|
||||||
func _send() -> void:
|
func _send() -> void:
|
||||||
if _send_pending:
|
if _send_pending:
|
||||||
return
|
return
|
||||||
var strippable_spaces := RegEx.create_from_string("(^\\s+|\\s+$)")
|
var body := NetworkChatProtocol.sanitize_body(_entry.text)
|
||||||
var body := strippable_spaces.sub(_entry.text, "", true)
|
|
||||||
if body.is_empty():
|
if body.is_empty():
|
||||||
close_chat()
|
close_chat()
|
||||||
return
|
return
|
||||||
_send_pending = true
|
_send_pending = true
|
||||||
_pending_send_body = NetworkChatProtocol.sanitize_body(body)
|
_pending_send_body = body
|
||||||
_entry.editable = false
|
_entry.editable = false
|
||||||
if not _service.send_local_message(
|
if not _service.send_local_message(
|
||||||
body,
|
body,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue