Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PORT] fix: add support for multibyte chars for truncate, stripped_input, tgui_input_text #5120

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions code/__HELPERS/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
if(isnull(user_input)) // User pressed cancel
return
if(no_trim)
return copytext(html_encode(user_input), 1, max_length)
return copytext_char(html_encode(user_input), 1, max_length)
else
return trim(html_encode(user_input), max_length) //trim is "outside" because html_encode can expand single symbols into multiple symbols (such as turning < into &lt;)

Expand All @@ -142,7 +142,7 @@
if(isnull(user_input)) // User pressed cancel
return
if(no_trim)
return copytext(html_encode(user_input), 1, max_length)
return copytext_char(html_encode(user_input), 1, max_length)
else
return trim(html_encode(user_input), max_length)

Expand Down Expand Up @@ -324,7 +324,7 @@
*/
/proc/truncate(text, max_length)
if(length(text) > max_length)
return copytext(text, 1, max_length)
return copytext_char(text, 1, max_length)
return text

//Returns a string with reserved characters and spaces before the first word and after the last word removed.
Expand Down
4 changes: 2 additions & 2 deletions code/modules/tgui_input/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@
switch(action)
if("submit")
if(max_length)
if(length(params["entry"]) > max_length)
if(length_char(params["entry"]) > max_length)
CRASH("[usr] typed a text string longer than the max length")
if(encode && (length(html_encode(params["entry"])) > max_length))
if(encode && (length_char(html_encode(params["entry"])) > max_length))
to_chat(usr, span_notice("Your message was clipped due to special character usage."))
set_entry(params["entry"])
closed = TRUE
Expand Down
Loading