From 6c4a80d2e54c8162d10f9ccbd2db45904335328b Mon Sep 17 00:00:00 2001 From: Charlie Nolan Date: Sun, 7 Apr 2024 02:59:15 -0700 Subject: [PATCH] Corrected a bunch of over-escaping. (#24876) * Corrected a bunch of over-escaping. * unundefine * Fixed #23759 * Apply suggestions from code review Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> * Review fix --------- Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> --- code/__HELPERS/text.dm | 4 ++++ .../gamemodes/miniantags/pulsedemon/pulsedemon.dm | 2 +- code/game/machinery/computer/communications.dm | 10 +++++----- .../objects/items/devices/radio/radio_objects.dm | 2 +- code/game/objects/items/devices/voice_changer.dm | 4 ++-- code/modules/admin/topic.dm | 2 +- code/modules/admin/verbs/pray.dm | 2 +- code/modules/events/blob/overmind.dm | 2 +- code/modules/hydroponics/seeds.dm | 2 +- code/modules/mob/dead/observer/observer_base.dm | 1 + code/modules/mob/living/carbon/carbon_procs.dm | 12 ++++++------ code/modules/mob/living/carbon/human/human_say.dm | 2 +- code/modules/mob/living/living_say.dm | 5 ++++- .../modules/mob/living/simple_animal/friendly/dog.dm | 6 +++--- code/modules/mob/living/simple_animal/parrot.dm | 4 ++-- .../mob/living/simple_animal/simple_animal.dm | 4 ++-- code/modules/mob/mob.dm | 10 +++++----- code/modules/mob/mob_say_base.dm | 10 +--------- code/modules/mob/mob_vars.dm | 4 ++++ code/modules/ruins/ghost_bar.dm | 1 + code/modules/station_goals/station_goal.dm | 2 +- 21 files changed, 48 insertions(+), 43 deletions(-) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index 787d1f1bdee..f34cb4fb3b0 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -38,6 +38,10 @@ /proc/sanitize(t, list/repl_chars = null) return html_encode(sanitize_simple(t,repl_chars)) +/// sanitize() with a pre-set list of characters to remove from IC speech. +/proc/sanitize_for_ic(t) + return sanitize(t, list("<" = "", ">" = "", "\[" = "", "]" = "", "{" = "", "}" = "")) + // Gut ANYTHING that isnt alphanumeric, or brackets /proc/paranoid_sanitize(t) var/regex/alphanum_only = regex("\[^a-zA-Z0-9# ,.?!:;()]", "g") diff --git a/code/game/gamemodes/miniantags/pulsedemon/pulsedemon.dm b/code/game/gamemodes/miniantags/pulsedemon/pulsedemon.dm index 6dbc087e0e5..fd11e7048cf 100644 --- a/code/game/gamemodes/miniantags/pulsedemon/pulsedemon.dm +++ b/code/game/gamemodes/miniantags/pulsedemon/pulsedemon.dm @@ -517,7 +517,7 @@ return FALSE if(sanitize) - message = trim_strip_html_properly(message) + message = sanitize_for_ic(trim(message)) if(stat) if(stat == DEAD) diff --git a/code/game/machinery/computer/communications.dm b/code/game/machinery/computer/communications.dm index 942ff0d194b..d8666b35d08 100644 --- a/code/game/machinery/computer/communications.dm +++ b/code/game/machinery/computer/communications.dm @@ -234,11 +234,11 @@ setMenuState(ui.user, COMM_SCREEN_STAT) if("setmsg1") - stat_msg1 = clean_input("Line 1", "Enter Message Text", stat_msg1) + stat_msg1 = tgui_input_text(ui.user, "Line 1", stat_msg1, "Enter Message Text", encode = FALSE) setMenuState(ui.user, COMM_SCREEN_STAT) if("setmsg2") - stat_msg2 = clean_input("Line 2", "Enter Message Text", stat_msg2) + stat_msg2 = tgui_input_text(ui.user, "Line 2", stat_msg2, "Enter Message Text", encode = FALSE) setMenuState(ui.user, COMM_SCREEN_STAT) if("nukerequest") @@ -246,7 +246,7 @@ if(centcomm_message_cooldown > world.time) to_chat(ui.user, "Arrays recycling. Please stand by.") return - var/input = tgui_input_text(ui.user, "Please enter the reason for requesting the nuclear self-destruct codes. Misuse of the nuclear request system will not be tolerated under any circumstances. Transmission does not guarantee a response.", "Self Destruct Code Request.") + var/input = tgui_input_text(ui.user, "Please enter the reason for requesting the nuclear self-destruct codes. Misuse of the nuclear request system will not be tolerated under any circumstances. Transmission does not guarantee a response.", "Self Destruct Code Request.", encode = FALSE) if(!input || ..() || !(is_authenticated(ui.user) >= COMM_AUTHENTICATION_CAPT)) return if(length(input) < COMM_CCMSGLEN_MINIMUM) @@ -264,7 +264,7 @@ if(centcomm_message_cooldown > world.time) to_chat(ui.user, "Arrays recycling. Please stand by.") return - var/input = tgui_input_text(ui.user, "Please choose a message to transmit to Centcomm via quantum entanglement. Please be aware that this process is very expensive, and abuse will lead to... termination. Transmission does not guarantee a response.", "CentComm Message") + var/input = tgui_input_text(ui.user, "Please choose a message to transmit to Centcomm via quantum entanglement. Please be aware that this process is very expensive, and abuse will lead to... termination. Transmission does not guarantee a response.", "CentComm Message", encode = FALSE) if(!input || ..() || !(is_authenticated(ui.user) >= COMM_AUTHENTICATION_CAPT)) return if(length(input) < COMM_CCMSGLEN_MINIMUM) @@ -283,7 +283,7 @@ if(centcomm_message_cooldown > world.time) to_chat(ui.user, "Arrays recycling. Please stand by.") return - var/input = tgui_input_text(ui.user, "Please choose a message to transmit to \[ABNORMAL ROUTING CORDINATES\] via quantum entanglement. Please be aware that this process is very expensive, and abuse will lead to... termination. Transmission does not guarantee a response.", "Send Message") + var/input = tgui_input_text(ui.user, "Please choose a message to transmit to \[ABNORMAL ROUTING CORDINATES\] via quantum entanglement. Please be aware that this process is very expensive, and abuse will lead to... termination. Transmission does not guarantee a response.", "Send Message", encode = FALSE) if(!input || ..() || !(is_authenticated(ui.user) >= COMM_AUTHENTICATION_CAPT)) return if(length(input) < COMM_CCMSGLEN_MINIMUM) diff --git a/code/game/objects/items/devices/radio/radio_objects.dm b/code/game/objects/items/devices/radio/radio_objects.dm index 514c33c672c..6757df97d49 100644 --- a/code/game/objects/items/devices/radio/radio_objects.dm +++ b/code/game/objects/items/devices/radio/radio_objects.dm @@ -818,7 +818,7 @@ GLOBAL_LIST_EMPTY(deadsay_radio_systems) to_chat(hearer, "[speaker_name] ([ghost_follow_link(subject, hearer)]) [message]") /obj/item/radio/headset/deadsay/talk_into(mob/living/M, list/message_pieces, channel, verbage) - var/message = sanitize(copytext(multilingual_to_message(message_pieces), 1, MAX_MESSAGE_LEN)) + var/message = copytext(multilingual_to_message(message_pieces), 1, MAX_MESSAGE_LEN) if(!message) return diff --git a/code/game/objects/items/devices/voice_changer.dm b/code/game/objects/items/devices/voice_changer.dm index 1fd3e0bdeb0..e7f34daa961 100644 --- a/code/game/objects/items/devices/voice_changer.dm +++ b/code/game/objects/items/devices/voice_changer.dm @@ -34,13 +34,13 @@ A.UpdateButtons() /obj/item/voice_changer/proc/set_voice(mob/user) - var/chosen_voice = clean_input("What voice would you like to mimic? Leave this empty to use the voice on your ID card.", "Set Voice Changer", voice, user) + var/chosen_voice = input("What voice would you like to mimic? Leave this empty to use the voice on your ID card.", "Set Voice Changer", voice, user) if(!chosen_voice) voice = null to_chat(user, "You are now mimicking the voice on your ID card.") return - voice = sanitize(copytext_char(chosen_voice, 1, MAX_MESSAGE_LEN)) + voice = sanitize_for_ic(copytext_char(chosen_voice, 1, MAX_MESSAGE_LEN)) to_chat(user, "You are now mimicking [voice].") /obj/item/voice_changer/voice_modulator diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index d70c4ab8ae1..904003160d9 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -2438,7 +2438,7 @@ if(!input) qdel(P) return - input = admin_pencode_to_html(html_encode(input)) // Encode everything from pencode to html + input = admin_pencode_to_html(input) // Encode everything from pencode to html var/customname = clean_input("Pick a title for the fax.", "Fax Title", null, owner) if(!customname) diff --git a/code/modules/admin/verbs/pray.dm b/code/modules/admin/verbs/pray.dm index aceb9476413..6385a515fdf 100644 --- a/code/modules/admin/verbs/pray.dm +++ b/code/modules/admin/verbs/pray.dm @@ -60,7 +60,7 @@ SEND_SOUND(X, sound('sound/effects/adminhelp.ogg')) /proc/ERT_Announce(text, mob/Sender, repeat_warning) - var/msg = sanitizeSafe(text) + var/msg = sanitize(text) var/insert_this = list(list( "time" = station_time_timestamp(), "sender_real_name" = "[Sender.real_name ? Sender.real_name : Sender.name]", diff --git a/code/modules/events/blob/overmind.dm b/code/modules/events/blob/overmind.dm index a06f0c1ce15..026712d5ec2 100644 --- a/code/modules/events/blob/overmind.dm +++ b/code/modules/events/blob/overmind.dm @@ -92,7 +92,7 @@ /mob/camera/blob/proc/blob_talk(message) log_say("(BLOB) [message]", src) - message = trim(copytext(sanitize(message), 1, MAX_MESSAGE_LEN)) + message = sanitize_for_ic(trim(copytext(message, 1, MAX_MESSAGE_LEN))) if(!message) return diff --git a/code/modules/hydroponics/seeds.dm b/code/modules/hydroponics/seeds.dm index 74393733a8c..2544e159bbb 100644 --- a/code/modules/hydroponics/seeds.dm +++ b/code/modules/hydroponics/seeds.dm @@ -334,7 +334,7 @@ return if(!(container ? container : src).Adjacent(user)) // Is the user next to the seed/container? return - variant = copytext(sanitize(html_encode(trim(V))), 1, 64) // Sanitization must happen after null check because it converts nulls to empty strings + variant = html_encode(copytext(trim(V), 1, 64)) if(variant == "") variant = null if(prev != variant) diff --git a/code/modules/mob/dead/observer/observer_base.dm b/code/modules/mob/dead/observer/observer_base.dm index d1c642334ed..a970301be26 100644 --- a/code/modules/mob/dead/observer/observer_base.dm +++ b/code/modules/mob/dead/observer/observer_base.dm @@ -40,6 +40,7 @@ GLOBAL_DATUM_INIT(ghost_crew_monitor, /datum/ui_module/crew_monitor/ghost, new) /// The "color" their runechat would have had var/alive_runechat_color = "#FFFFFF" hud_type = /datum/hud/ghost + speaks_ooc = TRUE /mob/dead/observer/New(mob/body=null, flags=1) set_invisibility(GLOB.observer_default_invisibility) diff --git a/code/modules/mob/living/carbon/carbon_procs.dm b/code/modules/mob/living/carbon/carbon_procs.dm index acbc04f6e80..81ba79c35d9 100644 --- a/code/modules/mob/living/carbon/carbon_procs.dm +++ b/code/modules/mob/living/carbon/carbon_procs.dm @@ -754,19 +754,19 @@ GLOBAL_LIST_INIT(ventcrawl_machinery, list(/obj/machinery/atmospherics/unary/ven user.set_machine(src) var/dat = {" - - + + "} - dat += "" - dat += "" + dat += "" - dat += "" + dat += "" if(istype(wear_mask, /obj/item/clothing/mask/muzzle)) var/obj/item/clothing/mask/muzzle/M = wear_mask diff --git a/code/modules/mob/living/carbon/human/human_say.dm b/code/modules/mob/living/carbon/human/human_say.dm index 1c9e0db7f61..f8d56e8934d 100644 --- a/code/modules/mob/living/carbon/human/human_say.dm +++ b/code/modules/mob/living/carbon/human/human_say.dm @@ -165,7 +165,7 @@ GLOBAL_LIST_INIT(soapy_words, list( S.message = uppertext(S.message) verb = "yells loudly" - if(span) + if(span && !speaks_ooc) S.message = "[S.message]" if(wear_mask) diff --git a/code/modules/mob/living/living_say.dm b/code/modules/mob/living/living_say.dm index 917bd1a9460..8ada26d0baa 100644 --- a/code/modules/mob/living/living_say.dm +++ b/code/modules/mob/living/living_say.dm @@ -112,7 +112,10 @@ GLOBAL_LIST_EMPTY(channel_to_radio_key) return FALSE if(sanitize) - message = trim_strip_html_properly(message) + if(speaks_ooc) + message = sanitize(message) + else + message = sanitize_for_ic(message) if(stat) if(stat == DEAD) diff --git a/code/modules/mob/living/simple_animal/friendly/dog.dm b/code/modules/mob/living/simple_animal/friendly/dog.dm index 6886ae40901..f1e718cacbf 100644 --- a/code/modules/mob/living/simple_animal/friendly/dog.dm +++ b/code/modules/mob/living/simple_animal/friendly/dog.dm @@ -172,9 +172,9 @@ popup.open() /mob/living/simple_animal/pet/dog/corgi/proc/get_invslot_content() - var/dat = "
Head:[html_encode(inventory_head)]" : "add_inv=head'>Nothing"]" - dat += "
Back:[html_encode(inventory_back)]" : "add_inv=back'>Nothing"]" - dat += "
Collar:[pcollar]" : "add_inv=collar'>Nothing"]" + var/dat = "
Head:[inventory_head]" : "add_inv=head'>Nothing"]" + dat += "
Back:[inventory_back]" : "add_inv=back'>Nothing"]" + dat += "
Collar:[pcollar]" : "add_inv=collar'>Nothing"]" return dat diff --git a/code/modules/mob/living/simple_animal/parrot.dm b/code/modules/mob/living/simple_animal/parrot.dm index 3fe5977d923..9b897ce6081 100644 --- a/code/modules/mob/living/simple_animal/parrot.dm +++ b/code/modules/mob/living/simple_animal/parrot.dm @@ -134,10 +134,10 @@ var/dat = {"
Left Hand:[(l_hand && !(l_hand.flags&ABSTRACT)) ? html_encode(l_hand) : "Empty"]
Right Hand:[(r_hand && !(r_hand.flags&ABSTRACT)) ? html_encode(r_hand) : "Empty"]
Left Hand:[(l_hand && !(l_hand.flags&ABSTRACT)) ? l_hand : "Empty"]
Right Hand:[(r_hand && !(r_hand.flags&ABSTRACT)) ? r_hand : "Empty"]
 
Back:[(back && !(back.flags&ABSTRACT)) ? html_encode(back) : "Empty"]" + dat += "
Back:[(back && !(back.flags&ABSTRACT)) ? back : "Empty"]" if(istype(wear_mask, /obj/item/clothing/mask) && istype(back, /obj/item/tank)) - dat += " [internal ? "Disable Internals" : "Set Internals"]" + dat += " [internal ? "Disable Internals" : "Set Internals"]" dat += "
 
Head:[(head && !(head.flags&ABSTRACT)) ? html_encode(head) : "Empty"]
Head:[(head && !(head.flags&ABSTRACT)) ? head : "Empty"]
Mask:[(wear_mask && !(wear_mask.flags&ABSTRACT)) ? html_encode(wear_mask) : "Empty"]
Mask:[(wear_mask && !(wear_mask.flags&ABSTRACT)) ? wear_mask : "Empty"]
"} - dat += "" + dat += "" if(can_collar) dat += "" - dat += "" + dat += "" dat += {"
Headset:[(ears && !(ears.flags&ABSTRACT)) ? html_encode(ears) : "Empty"]
Headset:[(ears && !(ears.flags&ABSTRACT)) ? ears : "Empty"]
 
Collar:[(pcollar && !(pcollar.flags&ABSTRACT)) ? html_encode(pcollar) : "Empty"]
Collar:[(pcollar && !(pcollar.flags&ABSTRACT)) ? pcollar : "Empty"]
Close diff --git a/code/modules/mob/living/simple_animal/simple_animal.dm b/code/modules/mob/living/simple_animal/simple_animal.dm index 9df1fb62e00..bf0315b7bcf 100644 --- a/code/modules/mob/living/simple_animal/simple_animal.dm +++ b/code/modules/mob/living/simple_animal/simple_animal.dm @@ -512,8 +512,8 @@ return user.set_machine(src) - var/dat = "
Collar:[(pcollar && !(pcollar.flags & ABSTRACT)) ? html_encode(pcollar) : "Empty"]
" - dat += "Close" + var/dat = "
Collar:[(pcollar && !(pcollar.flags & ABSTRACT)) ? pcollar : "Empty"]
" + dat += "Close" var/datum/browser/popup = new(user, "mob\ref[src]", "[src]", 440, 250) popup.set_content(dat) diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index dd7252e82cf..92845e0a4ca 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -605,11 +605,11 @@ GLOBAL_LIST_INIT(slot_equipment_priority, list( \ /mob/proc/show_inv(mob/user) user.set_machine(src) var/dat = {" - - + + "} dat += {"
Left Hand:[(l_hand && !(l_hand.flags&ABSTRACT)) ? html_encode(l_hand) : "Empty"]
Right Hand:[(r_hand && !(r_hand.flags&ABSTRACT)) ? html_encode(r_hand) : "Empty"]
Left Hand:[(l_hand && !(l_hand.flags&ABSTRACT)) ? l_hand : "Empty"]
Right Hand:[(r_hand && !(r_hand.flags&ABSTRACT)) ? r_hand : "Empty"]
 
- Close + Close "} var/datum/browser/popup = new(user, "mob\ref[src]", "[src]", 440, 250) @@ -732,7 +732,7 @@ GLOBAL_LIST_INIT(slot_equipment_priority, list( \ set category = "IC" msg = copytext(msg, 1, MAX_MESSAGE_LEN) - msg = sanitize_simple(html_encode(msg), list("\n" = "
")) + msg = sanitize(msg, list("\n" = "
")) var/combined = length(memory + msg) if(mind && (combined < MAX_PAPER_MESSAGE_LEN)) @@ -772,7 +772,7 @@ GLOBAL_LIST_INIT(slot_equipment_priority, list( \ to_chat(usr, "You have to be conscious to change your flavor text") return msg = copytext(msg, 1, MAX_MESSAGE_LEN) - msg = html_encode(msg) + msg = msg flavor_text = msg diff --git a/code/modules/mob/mob_say_base.dm b/code/modules/mob/mob_say_base.dm index 862fa495b39..9182f8e6e35 100644 --- a/code/modules/mob/mob_say_base.dm +++ b/code/modules/mob/mob_say_base.dm @@ -1,7 +1,3 @@ - -#define ILLEGAL_CHARACTERS_LIST list("<" = "", ">" = "", \ - "\[" = "", "]" = "", "{" = "", "}" = "") - /mob/proc/say() return @@ -26,16 +22,14 @@ else if(response == "No") return */ - message = replace_characters(message, ILLEGAL_CHARACTERS_LIST) set_typing_indicator(FALSE) usr.say(message) - /mob/verb/me_verb(message as text) set name = "Me" set category = "IC" - message = strip_html_properly(message) + message = sanitize(message) set_typing_indicator(FALSE, TRUE) if(use_me) @@ -222,5 +216,3 @@ for(var/datum/multilingual_say_piece/S in message_pieces) . += S.message + " " . = trim_right(.) - -#undef ILLEGAL_CHARACTERS_LIST diff --git a/code/modules/mob/mob_vars.dm b/code/modules/mob/mob_vars.dm index d22ef54752b..aa3f1f71098 100644 --- a/code/modules/mob/mob_vars.dm +++ b/code/modules/mob/mob_vars.dm @@ -246,3 +246,7 @@ var/next_click_modifier = 1 /// Tracks the open UIs that a mob has, used in TGUI for various things, such as updating UIs var/list/open_uis = list() + + /// Does this mob speak OOC? + /// Controls whether they can say some symbols. + var/speaks_ooc = FALSE diff --git a/code/modules/ruins/ghost_bar.dm b/code/modules/ruins/ghost_bar.dm index bfe72c4cf3b..51b0b4346bd 100644 --- a/code/modules/ruins/ghost_bar.dm +++ b/code/modules/ruins/ghost_bar.dm @@ -87,6 +87,7 @@ /obj/effect/mob_spawn/human/alive/ghost_bar/proc/equip_item(mob/living/carbon/human/H, path, slot) var/obj/item/I = new path(H) H.equip_or_collect(I, slot, TRUE) + H.speaks_ooc = TRUE return I /obj/structure/ghost_bar_cryopod diff --git a/code/modules/station_goals/station_goal.dm b/code/modules/station_goals/station_goal.dm index 5cf4c0b67d6..8e87f36795e 100644 --- a/code/modules/station_goals/station_goal.dm +++ b/code/modules/station_goals/station_goal.dm @@ -12,7 +12,7 @@ var/report_message = "Complete this goal." /datum/station_goal/proc/send_report() - GLOB.minor_announcement.Announce("Priority Nanotrasen directive received. Project \"[name]\" details inbound.", "Incoming Priority Message", 'sound/AI/commandreport.ogg') + GLOB.minor_announcement.Announce("Priority Nanotrasen directive received. Project \"[html_decode(name)]\" details inbound.", "Incoming Priority Message", 'sound/AI/commandreport.ogg') print_command_report(get_report(), "Nanotrasen Directive [pick(GLOB.phonetic_alphabet)] \Roman[rand(1,50)]", FALSE) on_report()