jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[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(-)

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>')

To view, visit change 489679. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I94b2c8411ca2e0d09113d79210eebf6563e78293
Gerrit-Change-Number: 489679
Gerrit-PatchSet: 4
Gerrit-Owner: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: D3r1ck01 <alangiderick@gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)