jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/770956 )

Change subject: [bugfix] Enable nested templates with MultiTemplateMatchBuilder
......................................................................

[bugfix] Enable nested templates with MultiTemplateMatchBuilder

Bug: T110529
Change-Id: I411cb16b144c187df16402073b394ca6d2560976
---
M pywikibot/textlib.py
1 file changed, 8 insertions(+), 5 deletions(-)

Approvals:
  Meno25: Looks good to me, but someone else must approve
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



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 https://gerrit.wikimedia.org/r/c/pywikibot/core/+/770956
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I411cb16b144c187df16402073b394ca6d2560976
Gerrit-Change-Number: 770956
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Jon Harald Søby <[email protected]>
Gerrit-Reviewer: Meno25 <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to