Skip to content

Commit

Permalink
Fixes xenos seeing raw html on paper (#5329)
Browse files Browse the repository at this point in the history
# About the pull request
Continuation of #4654 , to fix #4609 . This fix should make it so that
when xenos examine paper it no longer displays a blank page and the raw
html was replaced with the formatted scrambled message.

# Explain why it's good for the game

raw html is rather ugly




https://github.com/cmss13-devs/cmss13/assets/122310258/c279d8c8-e81e-477f-bcd0-cadc2bd32b4e



# Changelog

:cl:
fix: fixes xenos being able to view raw html on paper.
/:cl:

---------

Co-authored-by: harryob <[email protected]>
Co-authored-by: Drathek <[email protected]>
  • Loading branch information
3 people committed Dec 31, 2023
1 parent fc53e5b commit 686984d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
7 changes: 5 additions & 2 deletions code/game/supplyshuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,12 @@ GLOBAL_DATUM_INIT(supply_controller, /datum/controller/supply, new())
var/list/packages


/obj/item/paper/manifest/read_paper(mob/user)
/obj/item/paper/manifest/read_paper(mob/user, scramble = FALSE)
var/paper_info = info
if(scramble)
paper_info = stars_decode_html(info)
// Tossing ref in widow id as this allows us to read multiple manifests at same time
show_browser(user, "<BODY class='paper'>[info][stamps]</BODY>", null, "manifest\ref[src]", "size=550x650")
show_browser(user, "<BODY class='paper'>[paper_info][stamps]</BODY>", null, "manifest\ref[src]", "size=550x650")
onclose(user, "manifest\ref[src]")

/obj/item/paper/manifest/proc/generate_contents()
Expand Down
66 changes: 66 additions & 0 deletions code/modules/mob/mob_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,72 @@ GLOBAL_LIST_INIT(limb_types_by_name, list(
index++
return output_message

/**
* Summary: proc that parses an html input string and scrambles the non-html string contents.
*
* Arguments:
* * message - an html string value to be parsed and modified.
*
* Return:
* returns the parsed and modified html output with the text content being partially scrambled with asteriks
*/
/proc/stars_decode_html(message)
if(!length(message))
return

// boolean value to know if the current indexed element needs to be scrambled.
var/parsing_message = FALSE

// boolean values to know if we are currently inside a double or single quotation.
var/in_single_quote = FALSE
var/in_double_quote = FALSE

// string of what tag we're currently in
var/current_tag = ""
var/escaped_tag = FALSE

// string that will be scrambled
var/current_string_to_scramble = ""

// output string after parse
var/output_message = ""
for(var/character_index in 1 to length(message))
var/current_char = message[character_index]

// Apparent edge case safety, we only want to check the < and > on the edges of the tag.
if(!parsing_message)
if(current_char == "'")
in_single_quote = !in_single_quote
if(current_char == "\"")
in_double_quote = !in_double_quote
if(in_single_quote || in_double_quote)
output_message += current_char
continue

if(current_char == ">")
parsing_message = TRUE
output_message += current_char
current_tag += current_char
if(findtext(current_tag, "<style>") == 1 || findtext(current_tag, "<style ") == 1) // findtext because HTML doesn't care about anything after whitespace
escaped_tag = TRUE
else if(escaped_tag && (findtext(current_tag, "</style>") == 1 || findtext(current_tag, "</style ") == 1)) // 1 for findtext because we only care about the start of the string matching
escaped_tag = FALSE
continue
if(current_char == "<")
parsing_message = FALSE
current_tag = ""
if(length(current_string_to_scramble))
var/scrambled_string = stars(current_string_to_scramble)
output_message += scrambled_string
current_string_to_scramble = ""

if(parsing_message && !escaped_tag)
current_string_to_scramble += current_char
else
output_message += current_char
current_tag += current_char
return output_message

/proc/slur(phrase)
phrase = html_decode(phrase)
var/leng=length(phrase)
Expand Down
13 changes: 6 additions & 7 deletions code/modules/paperwork/paper.dm
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,22 @@
if(in_range(user, src) || isobserver(user))
if(!(istype(user, /mob/dead/observer) || istype(user, /mob/living/carbon/human) || isRemoteControlling(user)))
// Show scrambled paper if they aren't a ghost, human, or silicone.
if(photo_list)
for(var/photo in photo_list)
user << browse_rsc(photo_list[photo], photo)
show_browser(user, "<BODY class='paper'>[stars(info)][stamps]</BODY>", name, name, "size=650x700")
onclose(user, name)
read_paper(user,scramble = TRUE)
else
read_paper(user)
else
. += SPAN_NOTICE("It is too far away.")

/obj/item/paper/proc/read_paper(mob/user)
/obj/item/paper/proc/read_paper(mob/user, scramble = FALSE)
var/datum/asset/asset_datum = get_asset_datum(/datum/asset/simple/paper)
asset_datum.send(user)
if(photo_list)
for(var/photo in photo_list)
user << browse_rsc(photo_list[photo], photo)
show_browser(user, "<BODY class='paper'>[info][stamps]</BODY>", name, name, "size=650x700")
var/paper_info = info
if(scramble)
paper_info = stars_decode_html(info)
show_browser(user, "<BODY class='paper'>[paper_info][stamps]</BODY>", name, name, "size=650x700")
onclose(user, name)

/obj/item/paper/verb/rename()
Expand Down

0 comments on commit 686984d

Please sign in to comment.