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

Change subject: [bugfix] Fix textlib.removeDisabledParts method
......................................................................

[bugfix] Fix textlib.removeDisabledParts method

- textlib.NESTED_TEMPLATE_REGEX contains re.VERBOSE flag.
  Recomiling its pattern without this flag lead the regex to fail.
- reuse the cached precompiled patterns with their own flags instead
  of recompiling all regex patterns with generic IGNORECASE|DOTALL
  flag
- add some tests

Bug: T274138
Change-Id: I28e896aabe33b799747f18c1abcb48ccb49c0a7a
---
M pywikibot/textlib.py
M tests/textlib_tests.py
2 files changed, 22 insertions(+), 3 deletions(-)

Approvals:
  JJMC89: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index dc47927..4097a17 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -465,9 +465,9 @@
         tags = ('comment', 'includeonly', 'nowiki', 'pre', 'syntaxhighlight')
     tags = set(tags) - set(include)
     regexes = _get_regexes(tags, site)
-    toRemoveR = re.compile('|'.join(x.pattern for x in regexes),
-                           re.IGNORECASE | re.DOTALL)
-    return toRemoveR.sub('', text)
+    for regex in regexes:
+        text = regex.sub('', text)
+    return text


 def removeHTMLParts(text: str,
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index ce9e33a..e57c953 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -727,6 +727,25 @@
         self.assertTrue(self._mwpfh)


+class TestDisabledParts(DefaultDrySiteTestCase):
+
+    """Test the removeDisabledParts function in textlib."""
+
+    def test_remove_disabled_parts(self):
+        """Test removeDisabledParts function."""
+        tests = {
+            'comment': '<!-- No comment yet -->',
+            'link': '[[Target link]]',
+            'source': '<source>foo := bar</source>',
+            'template': '{{Infobox\n|foo = bar}}',
+            'unknown': '<Unknown>This is an unknown pattern</unKnown>',
+        }
+        for test, pattern in tests.items():
+            with self.subTest(test=test):
+                self.assertEqual(
+                    textlib.removeDisabledParts(pattern, tags=[test]), '')
+
+
 class TestReplaceLinks(TestCase):

     """Test the replace_links function in textlib."""

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/662715
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: I28e896aabe33b799747f18c1abcb48ccb49c0a7a
Gerrit-Change-Number: 662715
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: JJMC89 <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to