From a48545391ab87c9d4b7b380a5a902ba2a6ca104e Mon Sep 17 00:00:00 2001 From: PsiOmega Date: Sun, 15 Feb 2015 14:36:43 +0100 Subject: [PATCH] Fixes out of memory runtime errors and excessive HTML parsing. Announcements are no longer parsed twice, avoiding messages such as "T's nice". Fixes the strip_html_properly proc, to avoid out of memory runtimes. --- code/__HELPERS/text.dm | 15 +++++++++++++-- code/defines/procs/announce.dm | 2 +- code/game/machinery/computer/communications.dm | 2 +- .../computer3/computers/communications.dm | 2 +- code/modules/mob/living/silicon/ai/ai.dm | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index c14976bb78..27f5f98aa4 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -329,14 +329,25 @@ proc/TextPreview(var/string,var/len=40) //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) + if(!input) + return var/opentag = 1 //These store the position of < and > respectively. var/closetag = 1 while(1) opentag = findtext(input, "<") closetag = findtext(input, ">") - if(!closetag || !opentag) + if(closetag && opentag) + if(closetag < opentag) + input = copytext(input, (closetag + 1)) + else + input = copytext(input, 1, opentag) + copytext(input, (closetag + 1)) + else if(closetag || opentag) + if(opentag) + input = copytext(input, 1, opentag) + else + input = copytext(input, (closetag + 1)) + else break - input = copytext(input, 1, opentag) + copytext(input, (closetag + 1)) if(max_length) input = copytext(input,1,max_length) return sanitize(input) diff --git a/code/defines/procs/announce.dm b/code/defines/procs/announce.dm index b74f7a1c78..d3aef96c45 100644 --- a/code/defines/procs/announce.dm +++ b/code/defines/procs/announce.dm @@ -36,7 +36,7 @@ var/tmp/message_title = new_title ? new_title : title var/tmp/message_sound = new_sound ? sound(new_sound) : sound - message = html_encode(message) + message = trim_strip_html_properly(message) message_title = html_encode(message_title) Message(message, message_title) diff --git a/code/game/machinery/computer/communications.dm b/code/game/machinery/computer/communications.dm index f18d906383..a8403bbede 100644 --- a/code/game/machinery/computer/communications.dm +++ b/code/game/machinery/computer/communications.dm @@ -110,7 +110,7 @@ if(message_cooldown) usr << "Please allow at least one minute to pass between announcements" return - var/input = stripped_input(usr, "Please write a message to announce to the station crew.", "Priority Announcement") + var/input = input(usr, "Please write a message to announce to the station crew.", "Priority Announcement") if(!input || !(usr in view(1,src))) return crew_announcement.Announce(input) diff --git a/code/game/machinery/computer3/computers/communications.dm b/code/game/machinery/computer3/computers/communications.dm index bb268ba0c0..527a2e2c5a 100644 --- a/code/game/machinery/computer3/computers/communications.dm +++ b/code/game/machinery/computer3/computers/communications.dm @@ -115,7 +115,7 @@ if(message_cooldown) usr << "Please allow at least one minute to pass between announcements" return - var/input = stripped_input(usr, "Please write a message to announce to the station crew.", "Priority Announcement") + var/input = input(usr, "Please write a message to announce to the station crew.", "Priority Announcement") if(!input || !interactable()) return crew_announcement.Announce(input) diff --git a/code/modules/mob/living/silicon/ai/ai.dm b/code/modules/mob/living/silicon/ai/ai.dm index ff948d2387..62accdb198 100644 --- a/code/modules/mob/living/silicon/ai/ai.dm +++ b/code/modules/mob/living/silicon/ai/ai.dm @@ -368,7 +368,7 @@ var/list/ai_verbs_default = list( if(message_cooldown) src << "Please allow one minute to pass between announcements." return - var/input = stripped_input(usr, "Please write a message to announce to the station crew.", "A.I. Announcement") + var/input = input(usr, "Please write a message to announce to the station crew.", "A.I. Announcement") if(!input) return