Fix songbeamer import bug

This commit is contained in:
Simon Hanna 2017-03-29 14:05:08 +02:00
parent bd9eb0058a
commit b371e73acc
4 changed files with 31 additions and 3 deletions

View File

@ -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
@ -120,7 +118,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()

View File

@ -49,6 +49,13 @@ 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):
"""
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')))
class TestSongBeamerImport(TestCase):
"""

View File

@ -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"]
]
}

View File

@ -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….