jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] cosmetic_changes: Detect useless space at line end
......................................................................
[FIX] cosmetic_changes: Detect useless space at line end
It only trimmed useless spaces at the string end but not at each line end. And
instead of using two regexes to search for them it combines both into one regex
to only need to search once. It also adds the site parameter as the call has
been changed.
Change-Id: I8cf45d76441af49756f5933a651d07ecf61f2f82
---
M pywikibot/cosmetic_changes.py
M tests/cosmetic_changes_tests.py
2 files changed, 6 insertions(+), 4 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 93a19ba..3010ef3 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -617,13 +617,11 @@
def removeUselessSpaces(self, text):
"""Cleanup multiple or trailing spaces."""
- multipleSpacesR = re.compile(' +')
- spaceAtLineEndR = re.compile(' $')
exceptions = ['comment', 'math', 'nowiki', 'pre',
'startspace', 'table']
if self.site.sitename != 'wikipedia:cs':
exceptions.append('template')
- text = textlib.replaceExcept(text, multipleSpacesR, ' ', exceptions)
- text = textlib.replaceExcept(text, spaceAtLineEndR, '', exceptions)
+ text = textlib.replaceExcept(text, r'(?m) +( |$)', r'\1',
exceptions,
+ site=self.site)
return text
def removeNonBreakingSpaceBeforePercent(self, text):
diff --git a/tests/cosmetic_changes_tests.py b/tests/cosmetic_changes_tests.py
index c4fdc3e..17e270d 100644
--- a/tests/cosmetic_changes_tests.py
+++ b/tests/cosmetic_changes_tests.py
@@ -52,6 +52,10 @@
"""Test removeUselessSpaces method."""
self.assertEqual('Foo bar',
self.cct.removeUselessSpaces('Foo bar '))
+ self.assertEqual('Foo bar',
+ self.cct.removeUselessSpaces('Foo bar '))
+ self.assertEqual('Foo bar\nsna fu',
+ self.cct.removeUselessSpaces('Foo bar \nsna fu '))
# inside comments
self.assertEqual('<!--Foo bar -->',
self.cct.removeUselessSpaces('<!--Foo bar -->'))
--
To view, visit
https://gerrit.wikimedia.org/r/246795
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8cf45d76441af49756f5933a651d07ecf61f2f82
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>