jenkins-bot submitted this change.

View Change

Approvals: Meno25: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
[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.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I411cb16b144c187df16402073b394ca6d2560976
Gerrit-Change-Number: 770956
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Jon Harald Søby <jhsoby@gmail.com>
Gerrit-Reviewer: Meno25 <meno25mail@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged