Re: [Openlp-core] [Merge] lp:~thelinuxguy/openlp/fix-newline-bug into lp:openlp

2018-04-14 Thread Tim Bentley
Review: Needs Fixing

One minor fix as I do not like the rename of the field

Diff comments:

> === modified file 'openlp/core/common/__init__.py'
> --- openlp/core/common/__init__.py2018-02-24 16:10:02 +
> +++ openlp/core/common/__init__.py2018-04-14 20:05:07 +
> @@ -471,15 +471,15 @@
>  log.exception('Error detecting file encoding')
>  
>  
> -def normalize_str(irreg_str):
> +def normalize_str(string):

String is a data type so should not be used as a variable..

>  """
>  Normalize the supplied string. Remove unicode control chars and tidy up 
> white space.
>  
> -:param str irreg_str: The string to normalize.
> +:param str string: The string to normalize.
>  :return: The normalized string
>  :rtype: str
>  """
> -irreg_str = irreg_str.translate(REPLACMENT_CHARS_MAP)
> -irreg_str = CONTROL_CHARS.sub('', irreg_str)
> -irreg_str = NEW_LINE_REGEX.sub('\n', irreg_str)
> -return WHITESPACE_REGEX.sub(' ', irreg_str)
> +string = string.translate(REPLACMENT_CHARS_MAP)
> +string = CONTROL_CHARS.sub('', string)
> +string = NEW_LINE_REGEX.sub('\n', string)
> +return WHITESPACE_REGEX.sub(' ', string)


-- 
https://code.launchpad.net/~thelinuxguy/openlp/fix-newline-bug/+merge/343256
Your team OpenLP Core is subscribed to branch lp:openlp.

___
Mailing list: https://launchpad.net/~openlp-core
Post to : openlp-core@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openlp-core
More help   : https://help.launchpad.net/ListHelp


[Openlp-core] [Merge] lp:~thelinuxguy/openlp/fix-newline-bug into lp:openlp

2018-04-14 Thread Simon Hanna
Simon Hanna has proposed merging lp:~thelinuxguy/openlp/fix-newline-bug into 
lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #1727517 in OpenLP: "Unicode control chars causes song importer to crash"
  https://bugs.launchpad.net/openlp/+bug/1727517

For more details, see:
https://code.launchpad.net/~thelinuxguy/openlp/fix-newline-bug/+merge/343256

Fix the fix for 1727517
-- 
Your team OpenLP Core is requested to review the proposed merge of 
lp:~thelinuxguy/openlp/fix-newline-bug into lp:openlp.
=== modified file 'openlp/core/common/__init__.py'
--- openlp/core/common/__init__.py	2018-02-24 16:10:02 +
+++ openlp/core/common/__init__.py	2018-04-14 20:05:07 +
@@ -44,7 +44,7 @@
 
 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': '...',
@@ -471,15 +471,15 @@
 log.exception('Error detecting file encoding')
 
 
-def normalize_str(irreg_str):
+def normalize_str(string):
 """
 Normalize the supplied string. Remove unicode control chars and tidy up white space.
 
-:param str irreg_str: The string to normalize.
+:param str string: The string to normalize.
 :return: The normalized string
 :rtype: str
 """
-irreg_str = irreg_str.translate(REPLACMENT_CHARS_MAP)
-irreg_str = CONTROL_CHARS.sub('', irreg_str)
-irreg_str = NEW_LINE_REGEX.sub('\n', irreg_str)
-return WHITESPACE_REGEX.sub(' ', irreg_str)
+string = string.translate(REPLACMENT_CHARS_MAP)
+string = CONTROL_CHARS.sub('', string)
+string = NEW_LINE_REGEX.sub('\n', string)
+return WHITESPACE_REGEX.sub(' ', string)

=== modified file 'tests/functional/openlp_core/common/test_common.py'
--- tests/functional/openlp_core/common/test_common.py	2017-12-29 09:15:48 +
+++ tests/functional/openlp_core/common/test_common.py	2018-04-14 20:05:07 +
@@ -25,8 +25,8 @@
 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 @@
 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.

___
Mailing list: https://launchpad.net/~openlp-core
Post to : openlp-core@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openlp-core
More help   : https://help.launchpad.net/ListHelp


[Openlp-core] [Bug 1727517] Re: Unicode control chars causes song importer to crash

2018-04-14 Thread Simon Hanna
** Branch linked: lp:~thelinuxguy/openlp/fix-newline-bug

-- 
You received this bug notification because you are a member of OpenLP
Core, which is subscribed to OpenLP.
https://bugs.launchpad.net/bugs/1727517

Title:
  Unicode control chars causes song importer to crash

Status in OpenLP:
  Fix Committed

Bug description:
  https://support.openlp.org/scp/tickets.php?id=4330

  Traceback (most recent call last):

  File "openlp\core\ui\wizard.py", line 216, in on_current_id_changed

  File "openlp\plugins\songs\forms\songimportform.py", line 351, in
  perform_wizard

  File "openlp\plugins\songs\lib\importers\songshowplus.py", line 183,
  in do_import

  File "openlp\plugins\songs\lib\importers\songimport.py", line 356, in
  finish

  File "openlp\plugins\songs\lib\openlyricsxml.py", line 102, in
  add_verse_to_lyrics

  File "lxml.etree.pyx", line 2972, in lxml.etree.CDATA.__cinit__
  (src\lxml\lxml.etree.c:69195)

  File "apihelpers.pxi", line 1393, in lxml.etree._utf8
  (src\lxml\lxml.etree.c:27125)

  ValueError: All strings must be XML compatible: Unicode or ASCII, no
  NULL bytes or control characters

  
  Reproducible on ubuntu 17.10 trunk r2780

To manage notifications about this bug go to:
https://bugs.launchpad.net/openlp/+bug/1727517/+subscriptions

___
Mailing list: https://launchpad.net/~openlp-core
Post to : openlp-core@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openlp-core
More help   : https://help.launchpad.net/ListHelp