From c1085db91d2b112e9530bf39ba14128179e4597e Mon Sep 17 00:00:00 2001 From: Charlie Nolan Date: Fri, 4 Jul 2025 22:27:04 -0700 Subject: [PATCH] Prevent language-switching in the middle of a word or number. (#29721) --- code/_globalvars/_regexes.dm | 1 + code/modules/mob/mob_say_base.dm | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/code/_globalvars/_regexes.dm b/code/_globalvars/_regexes.dm index 505628f9732..ff25f6b9a27 100644 --- a/code/_globalvars/_regexes.dm +++ b/code/_globalvars/_regexes.dm @@ -2,4 +2,5 @@ GLOBAL_DATUM_INIT(filename_forbidden_chars, /regex, regex(@{""|[\\\n\t/?%*:|<>]| GLOBAL_DATUM_INIT(is_color, /regex, regex("^#\[0-9a-fA-F]{6}$")) GLOBAL_DATUM_INIT(regex_rgb_text, /regex, regex(@"^#?(([0-9a-fA-F]{8})|([0-9a-fA-F]{6})|([0-9a-fA-F]{3}))$")) GLOBAL_DATUM_INIT(is_http_protocol, /regex, regex("^https?://")) +GLOBAL_DATUM_INIT(is_alphanumeric, /regex, regex(@"[0-9a-zA-Z]")) GLOBAL_PROTECT(filename_forbidden_chars) diff --git a/code/modules/mob/mob_say_base.dm b/code/modules/mob/mob_say_base.dm index c3bc723c4d3..67c12eafb3d 100644 --- a/code/modules/mob/mob_say_base.dm +++ b/code/modules/mob/mob_say_base.dm @@ -159,8 +159,17 @@ /mob/proc/find_valid_prefixes(message) var/list/prefixes = list() // [["Common", start, end], ["Gutter", start, end]] + var/lower_message = lowertext(message) + var/is_alphanumeric = FALSE + var/was_alphanumeric = FALSE for(var/i in 1 to length(message)) - var/selection = trim_right(lowertext(copytext(message, i, i + 3))) + was_alphanumeric = is_alphanumeric + is_alphanumeric = GLOB.is_alphanumeric.Find(lower_message[i]) + if(was_alphanumeric) + // Language prefixes should not activate in the middle of a word or number. + continue + + var/selection = trim_right(copytext(lower_message, i, i + 3)) var/datum/language/L = GLOB.language_keys[selection] if(L != null && can_speak_language(L)) // What the fuck... remove the L != null check if you ever find out what the fuck is adding `null` to the languages list on absolutely random mobs... seriously what the hell... prefixes[++prefixes.len] = list(L, i, i + length(selection))