When the result of html_encode() called with a non-text value is stored to a variable, that variable points to what I assume is a temporary buffer, and is poisoned to change according to other writes to that buffer.
Behavior gets even weirder when text involving the poisoned value is sent to a browser. This manifested in SS13 as "[html_encode(name)] = [html_encode(value)]" lines with non-text values being replaced by other, later key/value pairs, which thus appeared twice in the output.
Code Snippet (if applicable) to Reproduce Problem:
. = ..()
var/t = "([html_encode(50)])"
src << "[length(t)]"
src << "_( [t] )_"
src << "[istext(t)]"
src << "[t:type]"
In addition, inserting another print of "_( [t] )_" before the first existing print causes all future prints to not appear.
_( (50) )_
runtime error: Cannot read "(50)".type
_( 0 )_
runtime error: Cannot read "1".type
Second code snippet:
. = ..()
var/t = "[html_encode(50)]<br>"
var/obj/O = new
for(var/key in O.vars)
t += "[key]<br>"
src << browse(t)
(... further output ...)
(no further output)
Does the problem occur:
Every time? Or how often? -- Every time
In other games? -- Yes
In other user accounts? -- Unknown
On other computers? -- Unknown
When does the problem NOT occur?
Introduced in 1420; works fine in 1419.
Call html_encode("[X]") everywhere you currently call html_encode(X).