Skip to content

Commit

Permalink
Don't add too many template args debug message for empty args
Browse files Browse the repository at this point in the history
It's not uncommon in non-en editions to have `{{{x||}}}` in templates.
  • Loading branch information
xxyzz committed May 7, 2024
1 parent c9440ce commit 50b9ee4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/wikitextprocessor/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,9 @@ def expand_args(coded: str, argmap: TemplateArgs) -> str:
continue
if kind == "A":
# Template argument reference
if len(args) > 2:
if len(args) > 2 and any(
len(arg.strip()) > 0 for arg in args[2:]
):
self.debug(
"too many args ({}) in argument "
"reference: {!r}".format(len(args), args),
Expand Down
8 changes: 8 additions & 0 deletions tests/test_node_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,11 @@ def test_auto_newline_before_paser_function(self):
self.ctx.start_page("newline")
self.assertEqual(self.ctx.expand("{{#if: true | text}}"), "text")
self.assertEqual(self.ctx.expand("{{#if: true | * list}}"), "\n* list")

def test_no_debug_message_for_extra_empty_template_argument(self):
# https://zh.wiktionary.org/wiki/Template:Context
# https://de.wiktionary.org/wiki/Vorlage:Literatur
self.ctx.start_page("")
self.ctx.add_page("Template:test", 10, "{{{1||}}}")
self.assertEqual(self.ctx.expand("{{test|t}}"), "t")
self.assertEqual(len(self.ctx.debugs), 0)

0 comments on commit 50b9ee4

Please sign in to comment.