From 7fcd166c67f66be91fb304153b1049867e4c234e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20J=C3=A4rventaus?= Date: Mon, 19 Oct 2026 13:05:08 +0300 Subject: [PATCH] When saving template arguments to self.cookies transform MAGIC_*BRACKET_CHAR MAGIC_*BRACKET_CHAR are two magical characters used in a kludge for pairs of square brackets (`[]`) that are annoying to parse, but this was one point where I hadn't realize we need to transform them back; template arguments would have leaked magical characters, and because they could contain other, even nested magical characters, this was difficult to notice, and square brackets are rare in text in wikitext anyhow. --- src/wikitextprocessor/core.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/wikitextprocessor/core.py b/src/wikitextprocessor/core.py index 741abe5..0aa2463 100644 --- a/src/wikitextprocessor/core.py +++ b/src/wikitextprocessor/core.py @@ -723,7 +723,12 @@ def _save_value( assert isinstance(args, (list, tuple)) assert nowiki in (True, False) # print("save_value", kind, args, nowiki) - args = tuple(args) + args = tuple( + arg.replace(MAGIC_LBRACKET_CHAR, "[").replace( + MAGIC_RBRACKET_CHAR, "]" + ) + for arg in args + ) v: CookieData = (kind, args, nowiki) if v in self.rev_ht: return self.rev_ht[v] @@ -962,8 +967,9 @@ def repl_extlink(m: re.Match) -> CookieChar: # text = re.sub(r"[^|]\}", r"\1}", text) # text = re.sub(r"[^|]\}", r"\1}", text) # text = re.sub(r"\|", "|", text) - text = text.replace(MAGIC_LBRACKET_CHAR, "[") - text = text.replace(MAGIC_RBRACKET_CHAR, "]") + text = text.replace(MAGIC_LBRACKET_CHAR, "[").replace( + MAGIC_RBRACKET_CHAR, "]" + ) return text def _template_to_body(self, title: str, text: Optional[str]) -> str: