Page MenuHomePhabricator

Parsoid interprets "X=..." in a parser function body as an key/value pair
Open, Needs TriagePublic

Description

In https://en.wikipedia.org/w/index.php?title=One_Direction&veaction=edit&section=19 an EasyTimeline is generated with a parser function. The body starts with "ImageSize=..." and this is interpreted as an attribute key, with the value being the rest of the body (despite it containing more key-value pairs).

In VE's template editor this looks like:

image.png (414×583 px, 61 KB)

Event Timeline

It might be fair, from an abstract representation of a parser function, to say that, unless Parser::SFH_OBJECT_ARGS is set, the function doesn't have named arguments.

The legacy implementation sort of bears that out by flattening the argument key/val to a string,
https://github.com/wikimedia/mediawiki/blob/master/includes/parser/Parser.php#L3422-L3431

But #tag does set Parser::SFH_OBJECT_ARGS and then arbitrarily chooses the first argument it receives from the parser, whether it's named or not, as the 'inner' content of the extension tag it's adapting,
https://github.com/wikimedia/mediawiki/blob/master/includes/parser/CoreParserFunctions.php#L1253

Parsoid interprets "X=..." in a parser function body as an key/value pair

Can you clarify what you mean by a parser function body?

The body starts with "ImageSize=..." and this is interpreted as an attribute key, with the value being the rest of the body (despite it containing more key-value pairs).

That seems ok, attributes are separated by | and, at least for templates, 0= is used to escape the use of = throughout an unnamed attribute value, but that's not going to work here.

I guess maybe regardless of Parser::SFH_OBJECT_ARGS they don't have named arguments.

SFH_OBJECT_ARGS isn't "named arguments", it is just "arguments given as preprocessor objects". The parser function is always responsible for parsing named arguments itself. I had a proposal to fix that: T204307.

That said, there seems to be a legit tokenizer issue here. I perhaps saw something similar with: <ref arg="foo</ref>"> but that's probably unrelated.

The wikitext in question is:

{{#tag:timeline|
ImageSize = width:900 height:auto barincrement:25
PlotArea = left:110 bottom:55 top:05 right:10
Alignbars = justify
...
}}

The bug does seem to be that parsoid thinks that parser functions have named arguments, whereas they do not -- unless SFH_NAMED_ARGS is present, which it is not because it is not implemented yet (T204307). So parsoid probably needs to have a separate mode for parsing the "arguments" of parser functions.