Repository navigation
Keep parser functions containing < or > as templates so enclosing templates are not lost - #375
Open
chinh13eboi2luae-ui wants to merge 1 commit into
Conversation
…plates are not lost
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #370.
Problem
A parser function whose first argument contains
<or>(for example{{#ifexpr: {{X}} <= 2 | ... }}) was not tokenized as a template. The tokenizer treats</>in a template name as invalid. When such a parser function was nested inside another template, the outer templates were dropped as well. For example,{{a|b={{s|{{#ifexpr: {{X}} <= 2 | {{Y}} | {{Z}} }}|02}}}}returned top-level templates['X', 'Y', 'Z']instead of['a']. The same happened with the infoboxbegins = {{start date|df=yes| {{#ifexpr: {{CURRENTMONTH}} <= 2 | ... }} |02|15}}line from the issue.Change
_verify_safe(Python) andTokenizer_verify_safe(C) now allow<and>while reading a template name if a top-level colon already appears in it. Only the text from the start of the name up to the first{is checked for the colon. In parser functions, the text after the colon is an argument, not a page title.<or>, such as{{DISPLAYTITLE:<i>X</i>}}or{{Foo:a<b}}. These now stay templates. Names without a colon, such as{{a<b|c}}, are still rejected as before. If the colon only appears after a nested template in the name, the old behavior is kept.tests/tokenizer/templates.mwtest:<=in a parser function,>=in a parser function, and the nested case from the issue.Validation (local Docker, Python 3.12)
tok_parse.cchange was not compiled or run, and the CTokenizer tests were skipped. The new.mwtestcases also run against CTokenizer when the extension is built, so CI should cover the C path..mwtestcases failed with PyTokenizer. A standalone reproduction also failed for all four issue inputs:<=,>=,1 <= 2, and the infobox line.str(parse(text)).= 2, no middle template,{{s|{{X}} < 2 | ...}})<b>tag inside nested templates still parses as a tag|c=3parameter keeps its value>=with no surrounding spaces works{{a<b|c}}still is not a templatepytest testspassed before and after the patch (1437 passed, 3 skipped after the patch), as didruff checkandruff format --check.Refs #370.
Validated with local Docker tests.
Docker validation
Base commit
3cb4dd29f264db331e9459c3302c313e3fe1d67f.Tests ran locally in an isolated Linux container with networking disabled.
Command
Base test output
Patched test output
The added regression tests also failed against the original source and passed with the complete patch.
Independent behavioral verification
Input: mwparserfromhell.parse('{{a|b={{s|{{#ifexpr: {{X}} <= 2 | {{Y}} | {{Z}} }}|02}}}}'), plus the >= variant, the '1 <= 2' variant and the real infobox 'begins' line. All of them are parsed with the pure-Python Tokenizer (use_c=False). Observed: the outer template is missing from the top-level templates. Expected: the top-level templates are exactly [outer], the parameter contains the middle template, and str(parse(text)) == text. CTokenizer is not covered because this image cannot compile it.
Exercised the
libraryinterface. The original scenario reproduced the defect; the fixed scenario and 2 additional behavior checks passed in 2 consecutive runs.