jenkins-bot merged this change.
[bugfix] Don't add blank line between categories and defaultsort
Bug: T155233
Change-Id: I03e885b912a5f8c165a421ee46ca06e41c10b1eb
---
M pywikibot/textlib.py
M tests/textlib_tests.py
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index a946186..2be1ea8 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1274,7 +1274,11 @@
'\nSee https://de.wikipedia.org/wiki/Hilfe:Personendaten'
'#Kopiervorlage')
return oldtext
- separator = site.family.category_text_separator
+ if re.search(r'\{\{ *(' + r'|'.join(site.getmagicwords('defaultsort'))
+ + r')', oldtext, flags=re.I):
+ separator = config.line_separator
+ else:
+ separator = site.family.category_text_separator
iseparator = site.family.interwiki_text_separator
separatorstripped = separator.strip()
iseparatorstripped = iseparator.strip()
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 6744d0b..45e09ef 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-2016
+# (C) Pywikibot team, 2011-2018
#
# Distributed under the terms of the MIT license.
#
@@ -208,6 +208,20 @@
config.line_separator = sep
self.assertEqual(old, new)
+ def test_indentation(self):
+ """Test indentation from previous block."""
+ # Block of text
+ old = 'Some text%(LS)s%(LS)s' % {'LS': config.LS} + self.old
+ cats = textlib.getCategoryLinks(old, site=self.site)
+ new = textlib.replaceCategoryLinks(old, cats, site=self.site)
+ self.assertEqual(old, new)
+
+ # DEFAULTSORT
+ old_ds = '{{DEFAULTSORT:key}}%(LS)s' % {'LS': config.LS} + self.old
+ cats_ds = textlib.getCategoryLinks(old_ds, site=self.site)
+ new_ds = textlib.replaceCategoryLinks(old_ds, cats_ds, site=self.site)
+ self.assertEqual(old_ds, new_ds)
+
def test_in_place_replace(self):
"""Test in-place category change is reversible."""
dummy = pywikibot.Category(self.site, 'foo')
To view, visit change 395008. To unsubscribe, visit settings.