mwparserfromhell icon indicating copy to clipboard operation
mwparserfromhell copied to clipboard

Multiple equal signs in a template are wrongly parsed as parameter name/value separator

Open lahwaacz opened this issue 7 years ago • 2 comments

Consider this wikicode:

{{echo|foo
== section ==
bar}}

After template expansion, using "Template:Echo" containing just {{{1}}}, MediaWiki parses it as

<p>foo
</p>
<h2><span class="mw-headline" id="section">section</span></h2>
<p>bar
</p>

I.e. everything between the | and }} is interpreted as one template parameter.

But mwparserfromhell parses it like a named parameter foo with the value = section ==\nbar:

In [1]: import mwparserfromhell

In [2]: wikicode = mwparserfromhell.parse("{{echo|foo\n== section ==\nbar}}")

In [3]: print(wikicode.get_tree())
{{
      echo
    | foo\n
    = = section ==\nbar
}}

In [4]: t = wikicode.filter_templates()[0]

In [5]: t.has("foo")
Out[5]: True

In [6]: t.get("foo").value
Out[6]: '= section ==\nbar'

Note that this behaviour is wrong only for named parameters, numbered parameters (like in {{echo|1=foo}}) behave like this even in MediaWiki.

lahwaacz avatar Aug 28 '18 11:08 lahwaacz

On a related note, mwparserfromhell parses URLs containing equal signs (=) inside templates differently depending on whether they are enclosed in brackets or not:

In [1]: import mwparserfromhell

In [2]: wikicode = mwparserfromhell.parse("{{echo|[http://example.com?foo=bar]}}")

In [2]: print(wikicode.get_tree())
{{
      echo
    | 1
    = [
            http://example.com?foo=bar
      ]
}}

In [3]: wikicode = mwparserfromhell.parse("{{echo|http://example.com?foo=bar}}")

In [3]: print(wikicode.get_tree())
{{
      echo
    | http://example.com?foo
    = bar
}}

This is also wrong, MediaWiki parses template parameters before external links, so it goes with the named parameter in both cases.

lahwaacz avatar Aug 28 '18 11:08 lahwaacz

Leaving this open due to the surprising (and somewhat upsetting) external link difference, but the template/heading conflict should be resolved.

earwig avatar Dec 21 '20 09:12 earwig