From 7182ff9c3fac2ec69dfbba2e97e315163b75a464 Mon Sep 17 00:00:00 2001 From: PsiOmega Date: Fri, 21 Nov 2014 18:19:04 +0100 Subject: [PATCH] /tg/ input stripping. Borrows /tg/ html stripping code. Ghosts are the first to be given this boon, they now have to deliberately emote things like "Spooky man and it#36&;s friends type crap". --- code/__HELPERS/text.dm | 27 +++++++++++++++++-- code/modules/mob/dead/observer/say.dm | 4 +-- code/modules/mob/living/carbon/alien/say.dm | 2 +- code/modules/mob/living/carbon/human/say.dm | 2 +- .../mob/living/carbon/human/whisper.dm | 5 ++-- code/modules/mob/living/silicon/say.dm | 2 +- .../simple_animal/borer/borer_captive.dm | 2 +- .../mob/living/simple_animal/borer/say.dm | 2 +- code/modules/mob/say.dm | 2 +- 9 files changed, 35 insertions(+), 13 deletions(-) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index a6a87c2bd0..9fbf8e81eb 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -70,10 +70,14 @@ else non_whitespace = 1 if(non_whitespace) return text //only accepts the text if it has some non-spaces -// Used to get a sanitized input. +// Used to get a properly sanitized input, of max_length /proc/stripped_input(var/mob/user, var/message = "", var/title = "", var/default = "", var/max_length=MAX_MESSAGE_LEN) var/name = input(user, message, title, default) - return strip_html_simple(name, max_length) + return strip_html_properly(name, max_length) + +// Used to get a trimmed, properly sanitized input, of max_length +/proc/trim_strip_input(var/mob/user, var/message = "", var/title = "", var/default = "", var/max_length=MAX_MESSAGE_LEN) + return trim(stripped_input(user, message, title, default, max_length)) //Filters out undesirable characters from names /proc/reject_bad_name(var/t_in, var/allow_numbers=0, var/max_length=MAX_NAME_LEN) @@ -314,3 +318,22 @@ proc/TextPreview(var/string,var/len=40) return string else return "[copytext(string, 1, 37)]..." + +//This proc strips html properly, but it's not lazy like the other procs. +//This means that it doesn't just remove < and > and call it a day. +//Also limit the size of the input, if specified. +/proc/strip_html_properly(var/input, var/max_length = MAX_MESSAGE_LEN) + var/opentag = 1 //These store the position of < and > respectively. + var/closetag = 1 + while(1) + opentag = findtext(input, "<") + closetag = findtext(input, ">") + if(!closetag || !opentag) + break + input = copytext(input, 1, opentag) + copytext(input, (closetag + 1)) + if(max_length) + input = copytext(input,1,max_length) + return input + +/proc/trim_strip_html_properly(var/input, var/max_length = MAX_MESSAGE_LEN) + return trim(strip_html_properly(input, max_length)) diff --git a/code/modules/mob/dead/observer/say.dm b/code/modules/mob/dead/observer/say.dm index 34a0d44d63..b5b819950c 100644 --- a/code/modules/mob/dead/observer/say.dm +++ b/code/modules/mob/dead/observer/say.dm @@ -1,5 +1,5 @@ /mob/dead/observer/say(var/message) - message = sanitize(copytext(message, 1, MAX_MESSAGE_LEN)) + message = strip_html_properly(message) if (!message) return @@ -18,7 +18,7 @@ /mob/dead/observer/emote(var/act, var/type, var/message) - message = sanitize(copytext(message, 1, MAX_MESSAGE_LEN)) + message = trim_strip_html_properly(message) if(!message) return diff --git a/code/modules/mob/living/carbon/alien/say.dm b/code/modules/mob/living/carbon/alien/say.dm index e58e193a6e..8b13a07fdc 100644 --- a/code/modules/mob/living/carbon/alien/say.dm +++ b/code/modules/mob/living/carbon/alien/say.dm @@ -7,7 +7,7 @@ src << "\red You cannot speak in IC (Muted)." return - message = trim(copytext(sanitize(message), 1, MAX_MESSAGE_LEN)) + message = trim_strip_html_properly(message) if(stat == 2) return say_dead(message) diff --git a/code/modules/mob/living/carbon/human/say.dm b/code/modules/mob/living/carbon/human/say.dm index 61223ee62d..4c039d1008 100644 --- a/code/modules/mob/living/carbon/human/say.dm +++ b/code/modules/mob/living/carbon/human/say.dm @@ -10,7 +10,7 @@ src << "\red You cannot speak in IC (Muted)." return - message = trim(copytext(sanitize(message), 1, MAX_MESSAGE_LEN)) + message = trim_strip_html_properly(message) if(stat == 2) return say_dead(message) diff --git a/code/modules/mob/living/carbon/human/whisper.dm b/code/modules/mob/living/carbon/human/whisper.dm index b365fb3922..109cfd601b 100644 --- a/code/modules/mob/living/carbon/human/whisper.dm +++ b/code/modules/mob/living/carbon/human/whisper.dm @@ -5,7 +5,8 @@ if(say_disabled) //This is here to try to identify lag problems usr << "\red Speech is currently admin-disabled." return - + + message = trim_strip_html_properly(message) log_whisper("[src.name]/[src.key] : [message]") if (src.client) @@ -21,8 +22,6 @@ if (src.stat) return - - message = trim(copytext(sanitize(message), 1, MAX_MESSAGE_LEN)) //made consistent with say if(name != GetVoice()) alt_name = "(as [get_id_name("Unknown")])" diff --git a/code/modules/mob/living/silicon/say.dm b/code/modules/mob/living/silicon/say.dm index 775ae5cd86..22db25d678 100644 --- a/code/modules/mob/living/silicon/say.dm +++ b/code/modules/mob/living/silicon/say.dm @@ -34,7 +34,7 @@ if (src.client.handle_spam_prevention(message,MUTE_IC)) return 0 - message = trim(copytext(sanitize(message), 1, MAX_MESSAGE_LEN)) + message = trim_strip_html_properly(message) if (stat == 2) return say_dead(message) diff --git a/code/modules/mob/living/simple_animal/borer/borer_captive.dm b/code/modules/mob/living/simple_animal/borer/borer_captive.dm index 808a2199f1..eacc058945 100644 --- a/code/modules/mob/living/simple_animal/borer/borer_captive.dm +++ b/code/modules/mob/living/simple_animal/borer/borer_captive.dm @@ -14,7 +14,7 @@ if(istype(src.loc,/mob/living/simple_animal/borer)) - message = trim(copytext(sanitize(message), 1, MAX_MESSAGE_LEN)) + message = trim_strip_html_properly(message) if (!message) return log_say("[key_name(src)] : [message]") diff --git a/code/modules/mob/living/simple_animal/borer/say.dm b/code/modules/mob/living/simple_animal/borer/say.dm index c0bfb0711f..5b52a5b473 100644 --- a/code/modules/mob/living/simple_animal/borer/say.dm +++ b/code/modules/mob/living/simple_animal/borer/say.dm @@ -1,6 +1,6 @@ /mob/living/simple_animal/borer/say(var/message) - message = trim(copytext(sanitize(message), 1, MAX_MESSAGE_LEN)) + message = trim_strip_html_properly(message) message = capitalize(message) if(!message) diff --git a/code/modules/mob/say.dm b/code/modules/mob/say.dm index 27ecfcc87e..9bc6fbe039 100644 --- a/code/modules/mob/say.dm +++ b/code/modules/mob/say.dm @@ -24,7 +24,7 @@ usr << "\red Speech is currently admin-disabled." return - message = trim(copytext(sanitize(message), 1, MAX_MESSAGE_LEN)) + message = strip_html_properly(message) set_typing_indicator(0) if(use_me)