diff --git a/src/utils/str.py b/src/utils/str.py index 24aa61706..a961b8ff4 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -93,10 +93,11 @@ 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') + starts_with_space = (s[0] in ' \n\t\r') + ends_with_space = (s[-1] in ' \n\t\r') if removeNewline: - s = ' '.join(filter(bool, s.split('\n'))) + newline_re = re.compile('[\r\n]+') + s = ' '.join(filter(bool, newline_re.split(s))) s = ' '.join(filter(bool, s.split('\t'))) s = ' '.join(filter(bool, s.split(' '))) if starts_with_space: diff --git a/test/test_utils.py b/test/test_utils.py index ce0c92c1f..cfc106af3 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -369,6 +369,7 @@ class StrTest(SupyTestCase): self.assertEqual(f('foo bar'), 'foo bar') self.assertEqual(f('foo\nbar'), 'foo bar') self.assertEqual(f('foo\tbar'), 'foo bar') + self.assertEqual(f('foo\rbar'), 'foo bar') def testNItems(self): nItems = utils.str.nItems