From 899c9243019b8890ece5970bb6328a9cd34a4d54 Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Fri, 23 Sep 2022 16:19:03 -0700 Subject: [PATCH] Update text.dm --- code/__HELPERS/text.dm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index dec44653af..cc44e98b2c 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -53,6 +53,36 @@ /proc/sanitize(t,list/repl_chars = null) return html_encode(sanitize_simple(t,repl_chars)) +//Used for preprocessing entered text +/proc/sanitize_rp(var/input, var/max_length = MAX_MESSAGE_LEN, var/encode = 1, var/trim = 1, var/extra = 1) + if(!input) + return + + if(max_length) + input = copytext(input,1,max_length) + + if(extra) + var/temp_input = replace_characters(input, list("\n"=" ","\t"=" "))//one character is replaced by two + if(length_char(input) < (length_char(temp_input) - 12)) //12 is the number of linebreaks allowed per message + input = replace_characters(temp_input,list(" "=" "))//replace again, this time the double spaces with single ones + + if(encode) + // The below \ escapes have a space inserted to attempt to enable Travis auto-checking of span class usage. Please do not remove the space. + //In addition to processing html, html_encode removes byond formatting codes like "\ red", "\ i" and other. + //It is important to avoid double-encode text, it can "break" quotes and some other characters. + //Also, keep in mind that escaped characters don't work in the interface (window titles, lower left corner of the main window, etc.) + input = html_encode(input) + else + //If not need encode text, simply remove < and > + //note: we can also remove here byond formatting codes: 0xFF + next byte + input = replace_characters(input, list("<"=" ", ">"=" ")) + + if(trim) + //Maybe, we need trim text twice? Here and before copytext? + input = trim(input) + + return input + //Runs sanitize and strip_html_simple //I believe strip_html_simple() is required to run first to prevent '<' from displaying as '<' after sanitize() calls byond's html_encode() /proc/strip_html(t,limit=MAX_MESSAGE_LEN)