jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/489679 )
Change subject: [bugfix] Fix header regex beginning with a comment ......................................................................
[bugfix] Fix header regex beginning with a comment
- still not working for `== Odkazy ==<!-- === Reference ===` - "header" regex is wrong name, it should be "heading", but it could be a breaking change, so leaving for now
Bug: T209712 Change-Id: I94b2c8411ca2e0d09113d79210eebf6563e78293 --- M pywikibot/textlib.py M tests/textlib_tests.py 2 files changed, 8 insertions(+), 3 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index 83cade7..fec2944 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -7,7 +7,7 @@
""" # -# (C) Pywikibot team, 2008-2018 +# (C) Pywikibot team, 2008-2019 # # Distributed under the terms of the MIT license. # @@ -280,7 +280,7 @@ 'file': (FILE_LINK_REGEX, lambda site: '|'.join(site.namespaces[6])), # section headers 'header': re.compile( - r'(?:(?<=\n)|\A)' + r'(?:(?<=\n)|\A)(?:<!--[\s\S]*?-->)*' r'=(?:.|<!--[\s\S]*?-->)+=' r' *(?:<!--[\s\S]*?--> *)*(?=\n|\Z)'), # external links diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py index 33a49cb..6b754da 100644 --- a/tests/textlib_tests.py +++ b/tests/textlib_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Test textlib module.""" # -# (C) Pywikibot team, 2011-2018 +# (C) Pywikibot team, 2011-2019 # # Distributed under the terms of the MIT license. # @@ -1221,6 +1221,11 @@ self.assertEqual(textlib.replaceExcept('\n==x==\n', 'x', 'y', ['header'], site=self.site), '\n==x==\n') + self.assertEqual(textlib.replaceExcept('\n<!--' + '\ncomment-->==x==<!--comment' + '\n-->\n', 'x', 'y', + ['header'], site=self.site), + '\n<!--\ncomment-->==x==<!--comment\n-->\n') self.assertEqual(textlib.replaceExcept('<pre>x</pre>', 'x', 'y', ['pre'], site=self.site), '<pre>x</pre>')
pywikibot-commits@lists.wikimedia.org