jenkins-bot submitted this change.
[bugfix] Enable nested templates with MultiTemplateMatchBuilder
Bug: T110529
Change-Id: I411cb16b144c187df16402073b394ca6d2560976
---
M pywikibot/textlib.py
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index dc313df..9d32247 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -195,7 +195,7 @@
"""Return a compiled regex to match template."""
# TODO: add ability to also match contents within the template
# TODO: add option for template to be None to match any template
- # TODO: use NESTED_TEMPLATE_REGEX with <parameters> instead of <params>
+ # TODO: merge regex with NESTED_TEMPLATE_REGEX
namespace = self.site.namespaces[10]
if isinstance(template, pywikibot.Page):
if template.namespace() == 10:
@@ -214,10 +214,13 @@
namespaces = [_ignore_case(ns) for ns in namespace]
namespaces.append(_ignore_case('msg'))
pattern = re.sub(r'_|\\ ', r'[_ ]', pattern)
- templateRegex = re.compile(
- r'\{\{ *(%(namespace)s:)?%(pattern)s(?P<parameters>\s*\|.+?|) *}}'
- % {'namespace': ':|'.join(namespaces), 'pattern': pattern},
- flags)
+ templateRegexP = (
+ r'{{\s*(%(namespace)s:)?%(pattern)s'
+ r'(?P<parameters>\s*\|[^{]+?'
+ r'((({{{[^{}]+?}}}|{{[^{}]+?}}|{[^{}]*?})[^{]*?)*?)?'
+ r'|)\s*}}'
+ ) % {'namespace': ':|'.join(namespaces), 'pattern': pattern}
+ templateRegex = re.compile(templateRegexP, flags)
return templateRegex
def search_any_predicate(self, templates):
To view, visit change 770956. To unsubscribe, or for help writing mail filters, visit settings.