diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index 8d939a97f..79f08cd39 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -44,7 +44,7 @@ log = logging.getLogger(__name__ + '.__init__') FIRST_CAMEL_REGEX = re.compile('(.)([A-Z][a-z]+)') SECOND_CAMEL_REGEX = re.compile('([a-z0-9])([A-Z])') -CONTROL_CHARS = re.compile(r'[\x00-\x1F\x7F-\x9F]') +CONTROL_CHARS = re.compile(r'[\x00-\08\x0E-\x1F\x7F-\x9F]') INVALID_FILE_CHARS = re.compile(r'[\\/:\*\?"<>\|\+\[\]%]') IMAGES_FILTER = None REPLACMENT_CHARS_MAP = str.maketrans({'\u2018': '\'', '\u2019': '\'', '\u201c': '"', '\u201d': '"', '\u2026': '...', diff --git a/tests/functional/openlp_core/common/test_common.py b/tests/functional/openlp_core/common/test_common.py index b4554d198..bd3e627c4 100644 --- a/tests/functional/openlp_core/common/test_common.py +++ b/tests/functional/openlp_core/common/test_common.py @@ -25,8 +25,8 @@ Functional tests to test the AppLocation class and related methods. from unittest import TestCase from unittest.mock import MagicMock, call, patch -from openlp.core.common import clean_button_text, de_hump, extension_loader, is_macosx, is_linux, is_win, \ - path_to_module, trace_error_handler +from openlp.core.common import (clean_button_text, de_hump, extension_loader, is_macosx, is_linux, + is_win, normalize_str, path_to_module, trace_error_handler) from openlp.core.common.path import Path @@ -211,6 +211,30 @@ class TestCommonFunctions(TestCase): assert is_win() is False, 'is_win() should return False' assert is_macosx() is False, 'is_macosx() should return False' + def test_normalize_str_leaves_newlines(self): + # GIVEN: a string containing newlines + str = 'something\nelse' + # WHEN: normalize is called + normalized_string = normalize_str(str) + # THEN: string is unchanged + assert normalized_string == str + + def test_normalize_str_removes_null_byte(self): + # GIVEN: a string containing newlines + str = 'somet\x00hing' + # WHEN: normalize is called + normalized_string = normalize_str(str) + # THEN: string is unchanged + assert normalized_string == 'something' + + def test_normalize_str_replaces_crlf_with_lf(self): + # GIVEN: a string containing crlf + str = 'something\r\nelse' + # WHEN: normalize is called + normalized_string = normalize_str(str) + # THEN: crlf is replaced with lf + assert normalized_string == 'something\nelse' + def test_clean_button_text(self): """ Test the clean_button_text() function.