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 1/3] 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)
From c6d908f578637b983d7a400a25bab4037c8e6ce2 Mon Sep 17 00:00:00 2001
From: silicons <2003111+silicons@users.noreply.github.com>
Date: Fri, 23 Sep 2022 16:27:24 -0700
Subject: [PATCH 2/3] Update say.dm
---
code/modules/mob/say.dm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/code/modules/mob/say.dm b/code/modules/mob/say.dm
index d8ef440ef9..ace632f3ed 100644
--- a/code/modules/mob/say.dm
+++ b/code/modules/mob/say.dm
@@ -54,7 +54,7 @@
to_chat(usr, "^^^----- The preceeding message has been DISCARDED for being over the maximum length of [MAX_MESSAGE_LEN]. It has NOT been sent! -----^^^")
return
- message = trim(copytext_char(sanitize(message), 1, MAX_MESSAGE_LEN))
+ message = trim(copytext_char(sanitize_rp(message), 1, MAX_MESSAGE_LEN))
clear_typing_indicator() // clear it immediately!
client?.last_activity = world.time
From 2b2aa2820796de8bb9484e40f20fa5cf68d809a6 Mon Sep 17 00:00:00 2001
From: VM_USER
Date: Sun, 25 Sep 2022 20:00:36 -0700
Subject: [PATCH 3/3] this is better
---
code/__HELPERS/text.dm | 30 ------------------------------
code/modules/mob/say.dm | 2 +-
2 files changed, 1 insertion(+), 31 deletions(-)
diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm
index cc44e98b2c..dec44653af 100644
--- a/code/__HELPERS/text.dm
+++ b/code/__HELPERS/text.dm
@@ -53,36 +53,6 @@
/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)
diff --git a/code/modules/mob/say.dm b/code/modules/mob/say.dm
index ace632f3ed..8261c5ae8e 100644
--- a/code/modules/mob/say.dm
+++ b/code/modules/mob/say.dm
@@ -54,7 +54,7 @@
to_chat(usr, "^^^----- The preceeding message has been DISCARDED for being over the maximum length of [MAX_MESSAGE_LEN]. It has NOT been sent! -----^^^")
return
- message = trim(copytext_char(sanitize_rp(message), 1, MAX_MESSAGE_LEN))
+ message = trim(html_encode(message), MAX_MESSAGE_LEN)
clear_typing_indicator() // clear it immediately!
client?.last_activity = world.time