jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/434109 )
Change subject: [bugfix] Fix regexes to allow <source> without parameter
......................................................................
[bugfix] Fix regexes to allow <source> without parameter
textlib regexes for source and syntaxhighlight elements assume there is
some HTML parameter. But it does not need to be.
Bug: T166506
Change-Id: I66475950c9371439c10aa597fb6c66eebad8c728
---
M pywikibot/textlib.py
M tests/textlib_tests.py
2 files changed, 12 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 5d3b445..9ba2b5f 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -250,7 +250,7 @@
'header': re.compile(r'(?m)^=+.+=+ *$'),
# preformatted text
'pre': re.compile(r'(?is)<pre[
>].*?</pre\s*>'),
- 'source': re.compile(r'(?is)<source
.*?</source\s*>'),
+ 'source': re.compile(r'(?is)<source[
>].*?</source\s*>'),
'score': re.compile(r'(?is)<score[
>].*?</score\s*>'),
# inline references
'ref': re.compile(r'(?is)<ref[ >].*?</ref>'),
@@ -327,7 +327,7 @@
# handle alias
if exc == 'source':
dontTouchRegexes.append(re.compile(
- r'(?is)<syntaxhighlight .*?</syntaxhighlight\s*>'))
+ r'(?is)<syntaxhighlight[
>].*?</syntaxhighlight\s*>'))
else:
# assume it's a regular expression
dontTouchRegexes.append(exc)
@@ -473,8 +473,8 @@
'includeonly':
r'<includeonly\s*>.*?</includeonly\s*>',
'nowiki': r'<nowiki\s*>.*?</nowiki\s*>',
'pre': r'<pre\s*>.*?</pre\s*>',
- 'source': r'<source .*?</source\s*>',
- 'syntaxhighlight': r'<syntaxhighlight
.*?</syntaxhighlight\s*>',
+ 'source': r'<source[ >].*?</source\s*>',
+ 'syntaxhighlight': r'<syntaxhighlight[
>].*?</syntaxhighlight\s*>',
}
if '*' in tags:
tags = list(regexes.keys())
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index bc9fa2e..648bcb1 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -1167,10 +1167,18 @@
'x', 'y',
['source'],
site=self.site),
'<source lang="xml">x</source>')
+ self.assertEqual(textlib.replaceExcept('<source>x</source>',
+ 'x', 'y',
['source'],
+ site=self.site),
+ '<source>x</source>')
self.assertEqual(textlib.replaceExcept('<syntaxhighlight
lang="xml">x</syntaxhighlight>',
'x', 'y',
['source'],
site=self.site),
'<syntaxhighlight
lang="xml">x</syntaxhighlight>')
+ self.assertEqual(
+
textlib.replaceExcept('<syntaxhighlight>x</syntaxhighlight>',
+ 'x', 'y', ['source'],
site=self.site),
+ '<syntaxhighlight>x</syntaxhighlight>')
self.assertEqual(textlib.replaceExcept('<includeonly>x</includeonly>',
'x', 'y',
['includeonly'],
site=self.site),
--
To view, visit
https://gerrit.wikimedia.org/r/434109
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I66475950c9371439c10aa597fb6c66eebad8c728
Gerrit-Change-Number: 434109
Gerrit-PatchSet: 3
Gerrit-Owner: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>