From 1a8347e62dce69beb171f64e75003f339d14f124 Mon Sep 17 00:00:00 2001 From: Birdtalon Date: Sun, 12 Nov 2023 23:04:22 +0000 Subject: [PATCH] sanitizes burrower tunnel names to alphanumeric only plus some common punctuation --- code/__HELPERS/text.dm | 5 +++++ code/modules/mob/living/carbon/xenomorph/Abilities.dm | 1 + .../carbon/xenomorph/abilities/burrower/burrower_powers.dm | 1 + 3 files changed, 7 insertions(+) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index d4d9eb320633..9a5989287772 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -30,6 +30,11 @@ text = replacetext(text, char, repl_chars[char]) return text +///Helper for only alphanumeric characters plus common punctuation, spaces, underscore and hyphen _ -. +/proc/replace_non_alphanumeric_plus(text) + var/regex/alphanumeric = regex(@{"[^a-z0-9 ,.?!\-_&]"}, "gi") + return alphanumeric.Replace(text, "") + /proc/readd_quotes(text) var/list/repl_chars = list(""" = "\"", "'" = "'") for(var/char in repl_chars) diff --git a/code/modules/mob/living/carbon/xenomorph/Abilities.dm b/code/modules/mob/living/carbon/xenomorph/Abilities.dm index 0a6e0ff2ca26..cb46b3c6cc26 100644 --- a/code/modules/mob/living/carbon/xenomorph/Abilities.dm +++ b/code/modules/mob/living/carbon/xenomorph/Abilities.dm @@ -75,6 +75,7 @@ X.tunnel_delay = 1 addtimer(CALLBACK(src, PROC_REF(cooldown_end)), 4 MINUTES) var/msg = strip_html(input("Add a description to the tunnel:", "Tunnel Description") as text|null) + msg = replace_non_alphanumeric_plus(msg) var/description if(msg) description = msg diff --git a/code/modules/mob/living/carbon/xenomorph/abilities/burrower/burrower_powers.dm b/code/modules/mob/living/carbon/xenomorph/abilities/burrower/burrower_powers.dm index 0501d0fc372e..1f31c4093623 100644 --- a/code/modules/mob/living/carbon/xenomorph/abilities/burrower/burrower_powers.dm +++ b/code/modules/mob/living/carbon/xenomorph/abilities/burrower/burrower_powers.dm @@ -189,6 +189,7 @@ return var/new_name = strip_html(input("Change the description of the tunnel:", "Tunnel Description") as text|null) + new_name = replace_non_alphanumeric_plus(new_name) if(new_name) new_name = "[new_name] ([get_area_name(T)])" log_admin("[key_name(src)] has renamed the tunnel \"[T.tunnel_desc]\" as \"[new_name]\".")