mwparserfromhell icon indicating copy to clipboard operation
mwparserfromhell copied to clipboard

#if: magic word is not parsed correctly when tags are inside the argument

Open lahwaacz opened this issue 3 years ago • 1 comments

Consider this wikicode:

>>> w = mwparserfromhell.parse("foo{{#if:<nowiki>bar</nowiki>|true|false}}baz")                                                                                                  
>>> print(w.get_tree())                                                                                                                                                          
foo{{#if:
<
      nowiki
>
      bar
</
      nowiki
>
|true|false}}baz

The {{#if:...}} magic word was clearly not parsed correctly, it is part of the surrounding text. It is probably because mwparserfromhell parses it as a regular template and tags are not allowed inside template names. However, MediaWiki allows tags inside the {{#if:...}} magic word.

lahwaacz avatar Aug 09 '20 12:08 lahwaacz

The same thing happens even when there are square brackets (without a link):

>>> w = mwparserfromhell.parse("foo{{#if:[bar]|true|false}}baz")
>>> print(w.get_tree())
foo{{#if:[bar]|true|false}}baz

lahwaacz avatar Aug 30 '21 18:08 lahwaacz