From 417be39b6a2c53517cd090c239487559165522b0 Mon Sep 17 00:00:00 2001
From: Fluffy <65877598+FluffyGhoster@users.noreply.github.com>
Date: Mon, 15 Apr 2024 10:43:52 +0200
Subject: [PATCH] Character preferences / records html decoding (#17796)
Character preferences / records are now decoded correctly for the
computer UI and character preference.
Known issues, that already existed before this PR: Security incident
reports cannot be imported (nothing appears), charges and details of an
incident do not show up on the PDA application

---
code/datums/records.dm | 22 ++++++++--
.../preference_setup/general/06_flavor.dm | 4 +-
.../file_system/programs/generic/records.dm | 6 +--
...luffyghost-characterprefshtmlencodings.yml | 41 +++++++++++++++++++
4 files changed, 64 insertions(+), 9 deletions(-)
create mode 100644 html/changelogs/fluffyghost-characterprefshtmlencodings.yml
diff --git a/code/datums/records.dm b/code/datums/records.dm
index d6a1c6b5d08..6acadb924f2 100644
--- a/code/datums/records.dm
+++ b/code/datums/records.dm
@@ -32,7 +32,14 @@
copied.vars[variable] = src.vars[variable]
return copied
-/datum/record/proc/Listify(var/deep = 1, var/list/excluded = list(), var/list/to_update) // Mostly to support old things or to use with serialization
+#define CONDITIONAL_HTML_DECODE(VAR)\
+ if(decode_html){\
+ if(istext(##VAR)){\
+ ##VAR = html_decode(##VAR);\
+ }\
+ }
+
+/datum/record/proc/Listify(var/deep = 1, var/list/excluded = list(), var/list/to_update, decode_html = FALSE) // Mostly to support old things or to use with serialization
var/list/record
if(!to_update)
. = record = list()
@@ -48,30 +55,37 @@
if(deep && (istype(src.vars[variable], /datum/record)))
if(to_update)
var/datum/record/R = src.vars[variable]
- var/listified = R.Listify(to_update = to_update[variable])
+ var/listified = R.Listify(to_update = to_update[variable], decode_html = decode_html)
if(listified)
record[variable] = listified
+ CONDITIONAL_HTML_DECODE(record[variable])
. = record
else
var/datum/record/R = src.vars[variable]
- record[variable] = R.Listify()
+ record[variable] = R.Listify(decode_html = decode_html)
+ //no escape
else if(deep && islist(src.vars[variable]) && is_list_containing_type(src.vars[variable], /datum/record))
record[variable] = list()
for(var/subr in src.vars[variable])
var/datum/record/r = subr
- record[variable] += list(r.Listify())
+ record[variable] += list(r.Listify(decode_html = decode_html))
var/llen = 0
if((variable in to_update) && islist(to_update[variable]))
var/list/L = to_update[variable]
llen = L.len
if(llen != LAZYLEN(record[variable]))
. = record
+ CONDITIONAL_HTML_DECODE(.)
else if(islist(src.vars[variable]) || istext(src.vars[variable]) || isnum(src.vars[variable]))
if(to_update && record[variable] != src.vars[variable])
record[variable] = src.vars[variable]
+ CONDITIONAL_HTML_DECODE(record[variable])
. = record
else if(!to_update)
record[variable] = src.vars[variable]
+ CONDITIONAL_HTML_DECODE(record[variable])
+
+#undef CONDITIONAL_HTML_DECODE
/datum/record/proc/Printify(var/list/excluded = list()) // Mostly to support old things or to use with serialization
diff --git a/code/modules/client/preference_setup/general/06_flavor.dm b/code/modules/client/preference_setup/general/06_flavor.dm
index 10300faece4..9441db35eef 100644
--- a/code/modules/client/preference_setup/general/06_flavor.dm
+++ b/code/modules/client/preference_setup/general/06_flavor.dm
@@ -124,7 +124,7 @@
"Set Flavor Text
",
"Set Robot Flavor Text
",
"
",
- "Signature: [pref.signature]
",
+ "Signature: [html_decode(pref.signature)]
",
"Edit Text | ",
"Edit Font | ",
"Help | ",
@@ -164,7 +164,7 @@
else if (href_list["edit_signature"])
switch (href_list["edit_signature"])
if ("text")
- var/new_sign = tgui_input_text(usr, "Please input the new character signature.", "New Signature", html2pencode(pref.signature))
+ var/new_sign = tgui_input_text(usr, "Please input the new character signature.", "New Signature", html2pencode(html_decode(pref.signature)), encode = FALSE)
if (!new_sign)
to_chat(usr, SPAN_NOTICE("Cancelled."))
if (pref.signature)
diff --git a/code/modules/modular_computers/file_system/programs/generic/records.dm b/code/modules/modular_computers/file_system/programs/generic/records.dm
index 1773c989cca..de1690d000f 100644
--- a/code/modules/modular_computers/file_system/programs/generic/records.dm
+++ b/code/modules/modular_computers/file_system/programs/generic/records.dm
@@ -137,14 +137,14 @@
"sex" = R.sex,
"age" = R.age,
"fingerprint" = R.fingerprint,
- "has_notes" = R.notes,
+ "has_notes" = html_decode(R.notes),
"physical_status" = R.physical_status,
"mental_status" = R.mental_status,
"species" = R.species,
"citizenship" = R.citizenship,
"religion" = R.religion,
"employer" = R.employer,
- "notes" = R.notes,
+ "notes" = html_decode(R.notes),
"blood" = R.medical ? R.medical.blood_type : null,
"dna" = R.medical ? R.medical.blood_dna : null,
"ccia_notes" = R.ccia_record,
@@ -171,7 +171,7 @@
excluded += "security"
if(!(records_type & RECORD_MEDICAL))
excluded += "medical"
- var/returned = active.Listify(1, excluded, data["active"])
+ var/returned = active.Listify(1, excluded, data["active"], decode_html = TRUE)
if(returned)
data["active"] = returned
else
diff --git a/html/changelogs/fluffyghost-characterprefshtmlencodings.yml b/html/changelogs/fluffyghost-characterprefshtmlencodings.yml
new file mode 100644
index 00000000000..2cf97c908b2
--- /dev/null
+++ b/html/changelogs/fluffyghost-characterprefshtmlencodings.yml
@@ -0,0 +1,41 @@
+################################
+# Example Changelog File
+#
+# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
+#
+# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
+# When it is, any changes listed below will disappear.
+#
+# Valid Prefixes:
+# bugfix
+# wip (For works in progress)
+# tweak
+# soundadd
+# sounddel
+# rscadd (general adding of nice things)
+# rscdel (general deleting of nice things)
+# imageadd
+# imagedel
+# maptweak
+# spellcheck (typo fixes)
+# experiment
+# balance
+# admin
+# backend
+# security
+# refactor
+#################################
+
+# Your name.
+author: FluffyGhost
+
+# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
+delete-after: True
+
+# Any changes you've made. See valid prefix list above.
+# INDENT WITH TWO SPACES. NOT TABS. SPACES.
+# SCREW THIS UP AND IT WON'T WORK.
+# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries.
+# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog.
+changes:
+ - bugfix: "Character preferences / records are now decoded correctly for the computer UI and character preference."