From fe39d35b2faf56332001f9a7978695ca464adab7 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 4 Jan 2013 22:28:44 +0100 Subject: [PATCH] core: Fix normalizeWhitespace handling of new lines. --- src/utils/str.py | 5 +++-- test/test_i18n.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utils/str.py b/src/utils/str.py index ed0354022..16a44ae34 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -55,13 +55,14 @@ def rsplit(s, sep=None, maxsplit=-1): else: return s.rsplit(sep, maxsplit) -def normalizeWhitespace(s, removeNewline=False): +def normalizeWhitespace(s, removeNewline=True): """Normalizes the whitespace in a string; \s+ becomes one space.""" if not s: return str(s) # not the same reference starts_with_space = (s[0] in ' \n\t') ends_with_space = (s[-1] in ' \n\t') - s = ('' if removeNewline else ' ').join(filter(bool, s.split('\n'))) + if removeNewline: + s = ' '.join(filter(bool, s.split('\n'))) s = ' '.join(filter(bool, s.split('\t'))) s = ' '.join(filter(bool, s.split(' '))) if starts_with_space: diff --git a/test/test_i18n.py b/test/test_i18n.py index 185d39504..c4ec68ad8 100644 --- a/test/test_i18n.py +++ b/test/test_i18n.py @@ -39,7 +39,7 @@ _ = PluginInternationalization() @internationalizeDocstring def foo(): - 'The operation succeeded.' + """The operation succeeded.""" pass class I18nTestCase(SupyTestCase): @@ -49,6 +49,8 @@ class I18nTestCase(SupyTestCase): self.assertEqual(_(msg_en), msg_fr) conf.supybot.language.setValue('en') self.assertEqual(_(msg_en), msg_en) + multiline = '%s\n\n%s' % (msg_en, msg_en) + self.assertEqual(_(multiline), multiline) def testDocstring(self): self.assertEqual(foo.__doc__, msg_en)