Page MenuHomePhabricator

-{{{ doesn't work through frame:preprocess after being unstripped from nowiki tags
Closed, InvalidPublic

Description

Steps to reproduce:
Create Module:Preprocess with the following content:

local p = {}
function p.main(frame)
     return frame:preprocess(mw.text.unstripNoWiki(frame.args[1]))
end
return p

On a different page, write and preview the code {{#invoke:Preprocess|main|<nowiki>-{{{argname}}}</nowiki>}}.

Expected result: since the argname argument is not defined, the code returns -{{{argname}}} without any preprocessing.
Actual result: The argname template gets expanded inside the curly braces, resulting in -{<transclusion of Template:argname>}

Event Timeline

Anomie subscribed.

On a different page, write and preview the code {{#invoke:Preprocess|main|<nowiki>-{{{argname}}</nowiki>}}.

First, you're missing a } in there. Try {{#invoke:Preprocess|main|<nowiki>-{{{argname}}}</nowiki>}} instead.

Second, -{ is language converter markup, so when the parser sees -{{{argname}}} it interprets it as -{ (unclosed, but language converter doesn't care about that) followed by {{argname}} followed by }. See https://www.mediawiki.org/wiki/Writing_systems/Syntax for some details.

First, you're missing a } in there. Try {{#invoke:Preprocess|main|<nowiki>-{{{argname}}}</nowiki>}} instead.

Yes, I did make a typo in my steps, but the same bug still exists even with the } added.

Then why does this work when done outside of nowiki tags?

-{{{argname}}} and {{#invoke:Preprocess|main|-{{{argname}}}}} both work as expected. Why is the -{ being interpred differently through frame:preprocess than the regular parser?

Ah, it looks like I was mistaken about it being interpreted as language converter markup. Instead what's happening is that <nowiki>-{{{argname}}}</nowiki> becomes -&#123;{{argname}}} so -{ isn't interpreted as language converter markup. But then when that goes through the preprocessor again, it's obviously interpreted as a template transclusion.

Restricted Application added a subscriber: jeblad. · View Herald TranscriptOct 16 2020, 5:28 PM

I just ran into (what I think is) this with the construct:

{|
|-{{table style|bb}}
| &nbsp;
|}

(the template generates a style attribute with pre-defined user-selected CSS rules; in the example: style="border-bottom: 1px solid black;")

Feeding this to Template:test case nowiki (which, I gather, ends up feeding it to the preprocessor) will trigger test failure as written, but come back green if a space is inserted between the table row markup (|-) and the template invocation.

Feeding the same code to Special:ExpandTemplates shows no difference anywhere (wikicode/XML/HTML), which suggests the possibility that there's some kind of special casing going on in the path in and on the way out and that isn't getting applied when called via Scribunto's frame:preprocess(). Maybe there's a tokenizer in there that keeps the |- separate from the {{, but frame:preprocess() ends up seeing it as a continuous string? Is the hyphen getting HTML entity-escaped on the way in (to avoid triggering lang. converter) and unescaped on the way out, and the latter step is for some reason not getting applied when triggered from Lua?