jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/453302 )
Change subject: pywikibot/textlib.py: Fix header regex to allow comments ......................................................................
pywikibot/textlib.py: Fix header regex to allow comments
This change fixes a bug in header regex that made it not detect headers which contained a comment after the header or a comment containing a \n within the header.
Related bug report on the mailing list: https://lists.wikimedia.org/pipermail/pywikibot/2018-August/009874.html
Change-Id: Id21200e596b6689c7bed35d0865cad5504be1676 --- M pywikibot/textlib.py M tests/cosmetic_changes_tests.py 2 files changed, 16 insertions(+), 1 deletion(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index e6ee2c1..700d82f 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -272,7 +272,10 @@ # files 'file': (FILE_LINK_REGEX, lambda site: '|'.join(site.namespaces[6])), # section headers - 'header': re.compile(r'(?:(?<=\n)|\A)=+.+=+ *(?=\n|\Z)'), + 'header': re.compile( + r'(?:(?<=\n)|\A)' + r'=(?:.|<!--[\s\S]*?-->)+=' + r' *(?:<!--[\s\S]*?--> *)*(?=\n|\Z)'), # external links 'hyperlink': compileLinkR(), # also finds links to foreign sites with preleading ":" diff --git a/tests/cosmetic_changes_tests.py b/tests/cosmetic_changes_tests.py index b1c6361..d5354c0 100644 --- a/tests/cosmetic_changes_tests.py +++ b/tests/cosmetic_changes_tests.py @@ -332,6 +332,18 @@ self.cct.removeEmptySections('\n==Bar==\n[[cs:Foo]]' '\n[[Category:Baz]]'))
+ def test_remove_empty_sections_with_heading_comments(self): + """Test removeEmptySections with comments in the section headings.""" + self.assertEqual( + '==2==<!--c--> <!--\n-->\nt', + self.cct.removeEmptySections('==1==\n==2==<!--c--> <!--\n-->\nt')) + self.assertEqual( + '==2== <!--c-->\nt', + self.cct.removeEmptySections('==1==\n==2== <!--c-->\nt')) + self.assertEqual( + '==2<!--\n-->==\nt', + self.cct.removeEmptySections('==1==\n==2<!--\n-->==\nt')) + def test_translateAndCapitalizeNamespaces(self): """Test translateAndCapitalizeNamespaces method.""" self.assertEqual(
pywikibot-commits@lists.wikimedia.org