From 172625b1936511455bfaec985a6f2c3b9b883f1f Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Mon, 13 Mar 2017 13:16:12 +0100 Subject: [PATCH 1/3] Make sure songbeamer songs are decoded correctly --- openlp/plugins/songs/lib/importers/songbeamer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/songbeamer.py b/openlp/plugins/songs/lib/importers/songbeamer.py index bec2c3811..b8170196c 100644 --- a/openlp/plugins/songs/lib/importers/songbeamer.py +++ b/openlp/plugins/songs/lib/importers/songbeamer.py @@ -22,8 +22,6 @@ """ The :mod:`songbeamer` module provides the functionality for importing SongBeamer songs into the OpenLP database. """ -import chardet -import codecs import logging import os import re @@ -119,7 +117,7 @@ class SongBeamerImport(SongImport): # The encoding should only be ANSI (cp1252), UTF-8, Unicode, Big-Endian-Unicode. # So if it doesn't start with 'u' we default to cp1252. See: # https://forum.songbeamer.com/viewtopic.php?p=419&sid=ca4814924e37c11e4438b7272a98b6f2 - if self.input_file_encoding.lower().startswith('u'): + if not self.input_file_encoding.lower().startswith('u'): self.input_file_encoding = 'cp1252' infile = open(import_file, 'rt', encoding=self.input_file_encoding) song_data = infile.readlines() From f7c944acc96e689b6b1ea65884cc59da08a724a8 Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Mon, 13 Mar 2017 13:42:20 +0100 Subject: [PATCH 2/3] Add test --- .../openlp_plugins/songs/test_songbeamerimport.py | 4 ++++ tests/resources/songbeamersongs/cp1252song.json | 8 ++++++++ tests/resources/songbeamersongs/cp1252song.sng | 15 +++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 tests/resources/songbeamersongs/cp1252song.json create mode 100644 tests/resources/songbeamersongs/cp1252song.sng diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py index 48de3a755..ccbd3a4d8 100644 --- a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py +++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py @@ -49,6 +49,10 @@ class TestSongBeamerFileImport(SongImportTestHelper): self.file_import([os.path.join(TEST_PATH, 'Lobsinget dem Herrn.sng')], self.load_external_result_data(os.path.join(TEST_PATH, 'Lobsinget dem Herrn.json'))) + def test_cp1252_encoded_file(self): + self.file_import([os.path.join(TEST_PATH, 'cp1252song.sng')], + self.load_external_result_data(os.path.join(TEST_PATH, 'cp1252song.json'))) + class TestSongBeamerImport(TestCase): """ diff --git a/tests/resources/songbeamersongs/cp1252song.json b/tests/resources/songbeamersongs/cp1252song.json new file mode 100644 index 000000000..5e92d7038 --- /dev/null +++ b/tests/resources/songbeamersongs/cp1252song.json @@ -0,0 +1,8 @@ +{ +"title": "Some Song", + "authors": ["Author"], + "verses" : [ + ["Here are a couple of \"weird\" chars’’’.\n", "v"], + ["Here is another one….\n\n", "v"] + ] +} diff --git a/tests/resources/songbeamersongs/cp1252song.sng b/tests/resources/songbeamersongs/cp1252song.sng new file mode 100644 index 000000000..f1288e731 --- /dev/null +++ b/tests/resources/songbeamersongs/cp1252song.sng @@ -0,0 +1,15 @@ +#LangCount=1 +#Editor=SongBeamer 4.28a +#Version=3 +#Format=F/K// +#TitleFormat=U +#Title=Some Song +#Author=Author +#Melody=Author +#(c)=No copyright +#CCLI=0000000000 +--- +Here are a couple of "weird" chars’’’. +--- +Here is another one…. + From e97c157a19b6a0b00bf5414c7fe3fff40bb01b94 Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Mon, 13 Mar 2017 13:43:55 +0100 Subject: [PATCH 3/3] Add comment --- tests/functional/openlp_plugins/songs/test_songbeamerimport.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py index ccbd3a4d8..f51f3ce0e 100644 --- a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py +++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py @@ -50,6 +50,9 @@ class TestSongBeamerFileImport(SongImportTestHelper): self.load_external_result_data(os.path.join(TEST_PATH, 'Lobsinget dem Herrn.json'))) def test_cp1252_encoded_file(self): + """ + Test that a CP1252 encoded file get's decoded properly. + """ self.file_import([os.path.join(TEST_PATH, 'cp1252song.sng')], self.load_external_result_data(os.path.join(TEST_PATH, 'cp1252song.json')))