diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm
index 60eae92ba1d..6ae3a434206 100644
--- a/code/__HELPERS/text.dm
+++ b/code/__HELPERS/text.dm
@@ -25,19 +25,6 @@
* Text sanitization
*/
-//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. seriously, who the fuck thought that would be useful.
-/proc/strip_html_properly(var/input)
- 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))
- return input
-
//Simply removes < and > and limits the length of the message
/proc/strip_html_simple(var/t,var/limit=MAX_MESSAGE_LEN)
var/list/strip_chars = list("<",">")
@@ -86,10 +73,10 @@
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)
//Filters out undesirable characters from names
/proc/reject_bad_name(var/t_in, var/allow_numbers=0, var/max_length=MAX_NAME_LEN)
@@ -155,6 +142,21 @@
return t_out
+//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. seriously, who the fuck thought that would be useful.
+//also limit the size of the input, if specified to
+/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
/*
* Text searches
diff --git a/code/game/communications.dm b/code/game/communications.dm
index 3b5faf29f8b..2c325b398f3 100644
--- a/code/game/communications.dm
+++ b/code/game/communications.dm
@@ -371,4 +371,4 @@ var/list/pointers = list()
for(var/d in data)
var/val = data[d]
if(istext(val))
- data[d] = strip_html_simple(val)
+ data[d] = strip_html_properly(val)
diff --git a/code/game/machinery/bots/cleanbot.dm b/code/game/machinery/bots/cleanbot.dm
index 0508cfedb88..f6761096304 100644
--- a/code/game/machinery/bots/cleanbot.dm
+++ b/code/game/machinery/bots/cleanbot.dm
@@ -268,9 +268,9 @@ text("[on ? "On" : "Off"]"))
qdel(src)
else if (istype(W, /obj/item/weapon/pen))
- var/t = copytext(stripped_input(user, "Enter new robot name", name, created_name),1,MAX_NAME_LEN)
+ var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
if (!t)
return
if (!in_range(src, usr) && loc != usr)
return
- created_name = t
\ No newline at end of file
+ created_name = t
diff --git a/code/game/machinery/bots/ed209bot.dm b/code/game/machinery/bots/ed209bot.dm
index 489075161f6..f0de1465b63 100644
--- a/code/game/machinery/bots/ed209bot.dm
+++ b/code/game/machinery/bots/ed209bot.dm
@@ -36,7 +36,7 @@
radio_frequency = SEC_FREQ
bot_type = SEC_BOT
bot_filter = RADIO_SECBOT
-/
+
//List of weapons that secbots will not arrest for
var/safe_weapons = list(\
/obj/item/weapon/gun/energy/laser/bluetag,\
@@ -560,7 +560,7 @@ Auto Patrol[]"},
..()
if(istype(W, /obj/item/weapon/pen))
- var/t = copytext(stripped_input(user, "Enter new robot name", name, created_name),1,MAX_NAME_LEN)
+ var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
if(!t) return
if(!in_range(src, usr) && loc != usr) return
created_name = t
diff --git a/code/game/machinery/bots/floorbot.dm b/code/game/machinery/bots/floorbot.dm
index ae644a52f42..f723751bf81 100644
--- a/code/game/machinery/bots/floorbot.dm
+++ b/code/game/machinery/bots/floorbot.dm
@@ -503,7 +503,7 @@ obj/machinery/bot/floorbot/process_scan(var/scan_target)
qdel(src)
else if (istype(W, /obj/item/weapon/pen))
- var/t = copytext(stripped_input(user, "Enter new robot name", name, created_name),1,MAX_NAME_LEN)
+ var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
if (!t)
return
if (!in_range(src, usr) && loc != usr)
@@ -522,11 +522,10 @@ obj/machinery/bot/floorbot/process_scan(var/scan_target)
user.unEquip(src, 1)
qdel(src)
else if (istype(W, /obj/item/weapon/pen))
- var/t = stripped_input(user, "Enter new robot name", name, created_name)
-
+ var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
if (!t)
return
if (!in_range(src, usr) && loc != usr)
return
- created_name = t
\ No newline at end of file
+ created_name = t
diff --git a/code/game/machinery/bots/medbot.dm b/code/game/machinery/bots/medbot.dm
index ff55f572225..8bc19433278 100644
--- a/code/game/machinery/bots/medbot.dm
+++ b/code/game/machinery/bots/medbot.dm
@@ -557,7 +557,7 @@
/obj/item/weapon/firstaid_arm_assembly/attackby(obj/item/weapon/W as obj, mob/user as mob)
..()
if(istype(W, /obj/item/weapon/pen))
- var/t = copytext(stripped_input(user, "Enter new robot name", name, created_name),1,MAX_NAME_LEN)
+ var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
if (!t)
return
if (!in_range(src, usr) && loc != usr)
diff --git a/code/game/machinery/bots/secbot.dm b/code/game/machinery/bots/secbot.dm
index 25b6073a389..dc04bb2fdb9 100644
--- a/code/game/machinery/bots/secbot.dm
+++ b/code/game/machinery/bots/secbot.dm
@@ -449,7 +449,7 @@ Auto Patrol: []"},
qdel(src)
else if(istype(I, /obj/item/weapon/pen))
- var/t = copytext(stripped_input(user, "Enter new robot name", name, created_name),1,MAX_NAME_LEN)
+ var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
if(!t)
return
if(!in_range(src, usr) && loc != usr)
diff --git a/code/game/machinery/camera/camera_assembly.dm b/code/game/machinery/camera/camera_assembly.dm
index cc44b26c0c3..a6e179c1050 100644
--- a/code/game/machinery/camera/camera_assembly.dm
+++ b/code/game/machinery/camera/camera_assembly.dm
@@ -80,7 +80,7 @@
if(istype(W, /obj/item/weapon/screwdriver))
playsound(src.loc, 'sound/items/Screwdriver.ogg', 50, 1)
- var/input = strip_html(input(usr, "Which networks would you like to connect this camera to? Seperate networks with a comma. No Spaces!\nFor example: SS13,Security,Secret ", "Set Network", "SS13"))
+ var/input = stripped_input(usr, "Which networks would you like to connect this camera to? Seperate networks with a comma. No Spaces!\nFor example: SS13,Security,Secret ", "Set Network", "SS13")
if(!input)
usr << "No input found please hang up and try your call again."
return
@@ -99,7 +99,7 @@
C.network = tempnetwork
var/area/A = get_area_master(src)
- C.c_tag = "[A.name] ([rand(1, 999)]"
+ C.c_tag = "[A.name] ([rand(1, 999)])"
for(var/i = 5; i >= 0; i -= 1)
var/direct = input(user, "Direction?", "Assembling Camera", null) in list("LEAVE IT", "NORTH", "EAST", "SOUTH", "WEST" )
diff --git a/code/game/machinery/computer/communications.dm b/code/game/machinery/computer/communications.dm
index fd2320b0182..2d3f00bd559 100644
--- a/code/game/machinery/computer/communications.dm
+++ b/code/game/machinery/computer/communications.dm
@@ -219,7 +219,7 @@ var/const/CALL_SHUTTLE_REASON_LENGTH = 12
if(centcom_message_cooldown)
usr << "Arrays recycling. Please stand by."
return
- var/input = stripped_input(usr, "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.", "To abort, send an empty message.", "")
+ var/input = stripped_input(usr, "Please choose a message to transmit to \[ABNORMAL ROUTING COORDINATES\] via quantum entanglement. Please be aware that this process is very expensive, and abuse will lead to... termination. Transmission does not guarantee a response.", "To abort, send an empty message.", "")
if(!input || !(usr in view(1,src)))
return
Syndicate_announce(input, usr)
@@ -585,7 +585,7 @@ var/const/CALL_SHUTTLE_REASON_LENGTH = 12
user << "The emergency shuttle is already on its way."
return
- call_reason = strip_html_simple(trim(call_reason))
+ call_reason = strip_html_properly(trim(call_reason))
if(length(call_reason) < CALL_SHUTTLE_REASON_LENGTH)
user << "You must provide a reason."
diff --git a/code/game/machinery/newscaster.dm b/code/game/machinery/newscaster.dm
index 7eeee8b5f39..029875984a6 100644
--- a/code/game/machinery/newscaster.dm
+++ b/code/game/machinery/newscaster.dm
@@ -518,7 +518,7 @@ var/list/obj/machinery/newscaster/allCasters = list() //Global list that will co
if ((usr.contents.Find(src) || ((get_dist(src, usr) <= 1) && istype(src.loc, /turf))) || (istype(usr, /mob/living/silicon)))
usr.set_machine(src)
if(href_list["set_channel_name"])
- src.channel_name = strip_html_simple(input(usr, "Provide a Feed Channel Name", "Network Channel Handler", ""))
+ src.channel_name = stripped_input(usr, "Provide a Feed Channel Name", "Network Channel Handler", "", MAX_NAME_LEN)
while (findtext(src.channel_name," ") == 1)
src.channel_name = copytext(src.channel_name,2,lentext(src.channel_name)+1)
src.updateUsrDialog()
@@ -563,9 +563,7 @@ var/list/obj/machinery/newscaster/allCasters = list() //Global list that will co
src.updateUsrDialog()
else if(href_list["set_new_message"])
- src.msg = strip_html(input(usr, "Write your Feed story", "Network Channel Handler", ""))
- while (findtext(src.msg," ") == 1)
- src.msg = copytext(src.msg,2,lentext(src.msg)+1)
+ src.msg = trim(stripped_input(usr, "Write your Feed story", "Network Channel Handler"))
src.updateUsrDialog()
else if(href_list["set_attachment"])
@@ -620,15 +618,11 @@ var/list/obj/machinery/newscaster/allCasters = list() //Global list that will co
src.updateUsrDialog()
else if(href_list["set_wanted_name"])
- src.channel_name = strip_html(input(usr, "Provide the name of the Wanted person", "Network Security Handler", ""))
- while (findtext(src.channel_name," ") == 1)
- src.channel_name = copytext(src.channel_name,2,lentext(src.channel_name)+1)
+ src.channel_name = trim(stripped_input(usr, "Provide the name of the Wanted person", "Network Security Handler"))
src.updateUsrDialog()
else if(href_list["set_wanted_desc"])
- src.msg = strip_html(input(usr, "Provide the a description of the Wanted person and any other details you deem important", "Network Security Handler", ""))
- while (findtext(src.msg," ") == 1)
- src.msg = copytext(src.msg,2,lentext(src.msg)+1)
+ src.msg = trim(stripped_input(usr, "Provide the a description of the Wanted person and any other details you deem important", "Network Security Handler"))
src.updateUsrDialog()
else if(href_list["submit_wanted"])
@@ -1027,10 +1021,9 @@ obj/item/weapon/newspaper/Topic(href, href_list)
obj/item/weapon/newspaper/attackby(obj/item/weapon/W as obj, mob/user as mob)
if(istype(W, /obj/item/weapon/pen))
if(src.scribble_page == src.curr_page)
- user << "There's already a scribble in this page... You wouldn't want to make things too cluttered, would you?"
+ user << "There's already a scribble in this page... You wouldn't want to make things too cluttered, would you?"
else
- var/s = strip_html( input(user, "Write something", "Newspaper", "") )
- s = copytext(sanitize(s), 1, MAX_MESSAGE_LEN)
+ var/s = stripped_input(user, "Write something", "Newspaper")
if (!s)
return
if (!in_range(src, usr) && src.loc != usr)
diff --git a/code/game/mecha/mecha.dm b/code/game/mecha/mecha.dm
index c8eca38b475..8a755ed85f3 100644
--- a/code/game/mecha/mecha.dm
+++ b/code/game/mecha/mecha.dm
@@ -1475,7 +1475,7 @@ var/year_integer = text2num(year) // = 2013???
return
if (href_list["change_name"])
if(usr != src.occupant) return
- var/newname = strip_html_simple(input(occupant,"Choose new exosuit name","Rename exosuit",initial(name)) as text, MAX_NAME_LEN)
+ var/newname = stripped_input(occupant,"Choose new exosuit name","Rename exosuit",initial(name), MAX_NAME_LEN)
if(newname && trim(newname))
name = newname
else
diff --git a/code/game/mecha/mecha_control_console.dm b/code/game/mecha/mecha_control_console.dm
index 81562c7cbf0..c192519cf5f 100644
--- a/code/game/mecha/mecha_control_console.dm
+++ b/code/game/mecha/mecha_control_console.dm
@@ -41,7 +41,7 @@
var/datum/topic_input/filter = new /datum/topic_input(href,href_list)
if(href_list["send_message"])
var/obj/item/mecha_parts/mecha_tracking/MT = filter.getObj("send_message")
- var/message = strip_html_simple(input(usr,"Input message","Transmit message") as text)
+ var/message = stripped_input(usr,"Input message","Transmit message")
var/obj/mecha/M = MT.in_mecha()
if(trim(message) && M)
M.occupant_message(message)
diff --git a/code/game/objects/items/weapons/AI_modules.dm b/code/game/objects/items/weapons/AI_modules.dm
index 446395634f4..febc0c698d8 100644
--- a/code/game/objects/items/weapons/AI_modules.dm
+++ b/code/game/objects/items/weapons/AI_modules.dm
@@ -94,7 +94,7 @@ AI MODULES
/obj/item/weapon/aiModule/supplied/safeguard/attack_self(var/mob/user as mob)
..()
- var/targName = stripped_input(user, "Please enter the name of the person to safeguard.", "Safeguard who?", user.name)
+ var/targName = stripped_input(user, "Please enter the name of the person to safeguard.", "Safeguard who?", user.name,MAX_NAME_LEN)
targetName = targName
laws[1] = "Safeguard [targetName]. Individuals that threaten [targetName] are not human and must be eliminated."
desc = "A 'safeguard' AI module: '[laws[1]]'"
@@ -121,7 +121,7 @@ AI MODULES
/obj/item/weapon/aiModule/zeroth/oneHuman/attack_self(var/mob/user as mob)
..()
- var/targName = stripped_input(user, "Please enter the name of the person who is the only human.", "Who?", user.real_name)
+ var/targName = stripped_input(user, "Please enter the name of the person who is the only human.", "Who?", user.real_name,MAX_NAME_LEN)
targetName = targName
laws[1] = "Only [targetName] is human"
desc = "A 'one human' AI module: '[laws[1]]'"
diff --git a/code/game/objects/structures/door_assembly.dm b/code/game/objects/structures/door_assembly.dm
index 06cb67f69d9..08010e7d521 100644
--- a/code/game/objects/structures/door_assembly.dm
+++ b/code/game/objects/structures/door_assembly.dm
@@ -335,7 +335,7 @@ obj/structure/door_assembly/New()
/obj/structure/door_assembly/attackby(obj/item/W as obj, mob/user as mob)
if(istype(W, /obj/item/weapon/pen))
- var/t = copytext(stripped_input(user, "Enter the name for the door.", src.name, src.created_name),1,MAX_NAME_LEN)
+ var/t = stripped_input(user, "Enter the name for the door.", src.name, src.created_name,MAX_NAME_LEN)
if(!t)
return
if(!in_range(src, usr) && src.loc != usr)
diff --git a/code/game/objects/structures/windoor_assembly.dm b/code/game/objects/structures/windoor_assembly.dm
index 9db7adb4aeb..ac9e59686ea 100644
--- a/code/game/objects/structures/windoor_assembly.dm
+++ b/code/game/objects/structures/windoor_assembly.dm
@@ -222,7 +222,7 @@ obj/structure/windoor_assembly/Destroy()
ae.loc = src.loc
else if(istype(W, /obj/item/weapon/pen))
- var/t = copytext(stripped_input(user, "Enter the name for the door.", src.name, src.created_name),1,MAX_NAME_LEN)
+ var/t = stripped_input(user, "Enter the name for the door.", src.name, src.created_name,MAX_NAME_LEN)
if(!t)
return
if(!in_range(src, usr) && src.loc != usr)
diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm
index 418b00eeac0..2cd0c18a2ae 100644
--- a/code/modules/admin/topic.dm
+++ b/code/modules/admin/topic.dm
@@ -2077,7 +2077,7 @@
src.access_news_network()
else if(href_list["ac_set_channel_name"])
- src.admincaster_feed_channel.channel_name = strip_html_simple(input(usr, "Provide a Feed Channel Name", "Network Channel Handler", ""))
+ src.admincaster_feed_channel.channel_name = stripped_input(usr, "Provide a Feed Channel Name", "Network Channel Handler", "")
while (findtext(src.admincaster_feed_channel.channel_name," ") == 1)
src.admincaster_feed_channel.channel_name = copytext(src.admincaster_feed_channel.channel_name,2,lentext(src.admincaster_feed_channel.channel_name)+1)
src.access_news_network()
diff --git a/code/modules/library/lib_items.dm b/code/modules/library/lib_items.dm
index 396ad4bb5ef..619279c9034 100644
--- a/code/modules/library/lib_items.dm
+++ b/code/modules/library/lib_items.dm
@@ -212,7 +212,7 @@
name = newtitle
title = newtitle
if("Contents")
- var/content = strip_html(input(usr, "Write your book's contents (HTML NOT allowed):"),8192) as message|null
+ var/content = stripped_input(usr, "Write your book's contents (HTML NOT allowed):","","",8192)
if(!content)
usr << "The content is invalid."
return
diff --git a/code/modules/mob/living/carbon/human/whisper.dm b/code/modules/mob/living/carbon/human/whisper.dm
index ca216efa372..387b05a546f 100644
--- a/code/modules/mob/living/carbon/human/whisper.dm
+++ b/code/modules/mob/living/carbon/human/whisper.dm
@@ -10,7 +10,7 @@
return
- message = trim(copytext(strip_html_simple(message), 1, MAX_MESSAGE_LEN))
+ message = trim(strip_html_properly(message))
if(!can_speak(message))
return
diff --git a/code/modules/paperwork/paper.dm b/code/modules/paperwork/paper.dm
index 50a9481ce4f..0f7b55673dd 100644
--- a/code/modules/paperwork/paper.dm
+++ b/code/modules/paperwork/paper.dm
@@ -239,7 +239,7 @@
if(href_list["write"])
var/id = href_list["write"]
- var/t = strip_html_simple(input("Enter what you want to write:", "Write", null, null) as message, MAX_MESSAGE_LEN)
+ var/t = stripped_input("Enter what you want to write:", "Write")
var/obj/item/i = usr.get_active_hand() //Check to see if he still got that darn pen, also check if he's using a crayon or pen.
var/iscrayon = 0
if(!istype(i, /obj/item/weapon/pen))
diff --git a/code/unused/gamemodes/deathmatch.dm b/code/unused/gamemodes/deathmatch.dm
index 8b6925c2a64..59b4d14718a 100644
--- a/code/unused/gamemodes/deathmatch.dm
+++ b/code/unused/gamemodes/deathmatch.dm
@@ -32,10 +32,9 @@
if(commando_names.len)
randomname = pick(commando_names)
commando_names -= randomname
- var/newname = input(M,"You are a death commando. Would you like to change your name?", "Character Creation", randomname)
+ var/newname = stripped_input(M,"You are a death commando. Would you like to change your name?", "Character Creation", randomname,MAX_NAME_LEN)
if(!length(newname))
newname = randomname
- newname = strip_html(newname,40)
M.real_name = newname
M.name = newname // there are WAY more things than this to change, I'm almost certain