ID:2586905
 
BYOND Version:513, 512, ...
Operating System:Any
Web Browser:Firefox 78.0
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary:

In the specific scenario in the test, a literal macro passed to a replacetext() inside a string interpolation passed through a defined macro to browse() chokes on the literal macro, but not other characters. The same scenario using output does not fail.


Numbered Steps to Reproduce Problem:

1. Build the snippet, click "browse_4a_define_text_interpolation_literal".

2. Note that the browser popup's contents is all on one line.

3. Try any other test (in the passing tab for ease) - note that they are one word per line in popups or output.


Code Snippet (if applicable) to Reproduce Problem:
//-- defines and vars --

#define to_output(target, content) target << (content)
#define to_browser(target, content, title) target << browse(content, title)

var/to_replace = "\n"
var/replace_with = "<BR>"

var/source_text = "some" + to_replace + "text" + to_replace + "here"
var/source_list = list("some", "text", "here")

// -- the problem test --

/mob/verb/browse_4a_define_text_interpolation_literal()
to_browser(usr, "[replacetext(source_text, "\n", replace_with)]", "window=browse_4a_define_text_interpolation_literal;size=300x100")

//-- other test variations with literals --

/mob/verb/output_2a_direct_interpolation_literal()
set category = "Passing"
usr << "[replacetext(source_text, "\n", replace_with)]"

/mob/verb/output_4a_define_interpolation_literal()
set category = "Passing"
to_output(usr, "[replacetext(source_text, "\n", replace_with)]")

/mob/verb/browse_2a_direct_text_interpolation_literal()
set category = "Passing"
usr << browse("[replacetext(source_text, "\n", replace_with)]", "window=browse_2_direct_text_interpolation;size=300x100")

/mob/verb/browse_4b_define_text_interpolation_literal_staged()
set category = "Passing"
var/check = "[replacetext(source_text, "\n", replace_with)]"
to_browser(usr, check, "window=browse_4b_define_text_interpolation_literal_staged;size=300x100")

//-- tests outputting to the main output --

/mob/verb/output_1_direct_bare()
set category = "Passing"
usr << replacetext(source_text, to_replace, replace_with)

/mob/verb/output_2_direct_interpolation()
set category = "Passing"
usr << "[replacetext(source_text, to_replace, replace_with)]"

/mob/verb/output_3_define_bare()
set category = "Passing"
to_output(usr, replacetext(source_text, to_replace, replace_with))

/mob/verb/output_4_define_interpolation()
set category = "Passing"
to_output(usr, "[replacetext(source_text, to_replace, replace_with)]")

//-- tests outputting to a popup window --

/mob/verb/browse_1_direct_text_bare()
set category = "Passing"
usr << browse(replacetext(source_text, to_replace, replace_with), "window=browse_1_direct_text_bare;size=300x100")

/mob/verb/browse_2_direct_text_interpolation()
set category = "Passing"
usr << browse("[replacetext(source_text, to_replace, replace_with)]", "window=browse_2_direct_text_interpolation;size=300x100")

/mob/verb/browse_3_define_text_bare()
set category = "Passing"
to_browser(usr, replacetext(source_text, to_replace, replace_with), "window=browse_3_define_text_bare;size=300x100")

/mob/verb/browse_4_define_text_interpolation()
set category = "Passing"
to_browser(usr, "[replacetext(source_text, to_replace, replace_with)]", "window=browse_4_define_text_interpolation;size=300x100")

/mob/verb/browse_5_define_text_concatenation()
set category = "Passing"
to_browser(usr, "<DIV>" + replacetext(source_text, to_replace, replace_with) + "</DIV>", "window=browse_5_define_text_concatenation;size=300x100")

/mob/verb/browse_6_define_list_bare()
set category = "Passing"
to_browser(usr, jointext(source_list, replace_with), "window=browse_6_define_list_bare;size=300x100")

/mob/verb/browse_7_define_list_interpolation()
set category = "Passing"
to_browser(usr, "[jointext(source_list, replace_with)]", "window=browse_7_define_list_interpolation;size=300x100")

//-- end --



Expected Results:

All of the tests output
"
some
text
here
"
In their respective outputs.


Actual Results:

Every test EXCEPT browse_4a succeeds. browse_4a instead does not carry out the expected replacement when the literal is a macro.
browse_4a_define_text_interpolation_literal is, inline:
:: a literal macro inside a replacetext() inside a string interpolation inside a defined macro that supplies the resulting string to a browse().

It is possible to vary the value used in the tests by modifying var/to_replace and the string literal passed to browse_4a.
This appears to occur because the escapes are oddly handled in this specific circumstance.

`\n`: https://i.imgur.com/ydFFnd1.png
`\t`: https://i.imgur.com/aytEJfC.png
`\ `: https://i.imgur.com/hASh0z5.png
`\"`: https://i.imgur.com/6BhBpFJ.png


Does the problem occur:

Yes.


When does the problem NOT occur?

It does not not occur.


Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)

N/A -- 513, 512, 511. That's old enough for me.


Workarounds:

1. Do not use a literal macro in this context. Define a constant, such as var/const/NEWLINE = "\n", and pass that instead.

2. Create the content string as a var with no other changes, then pass the var to the define (as in browse_4b).
Very likely related to id:2561405, and if so demonstrates that that one is indeed not a beta bug.
I think Exxion is correct that these two bugs are the same. Looking in the debugger, it appears the expression to find in replacetext() is "\nn" instead of "\n", so it indicates a parsing issue with the define.