diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py
index d9518bd50..21195096f 100644
--- a/openlp/core/lib/__init__.py
+++ b/openlp/core/lib/__init__.py
@@ -23,12 +23,11 @@
The :mod:`lib` module contains most of the components and libraries that make
OpenLP work.
"""
-
+import html
import logging
import os
import re
import math
-from distutils.version import LooseVersion
from PyQt5 import QtCore, QtGui, Qt, QtWidgets
@@ -36,6 +35,8 @@ from openlp.core.common import translate
log = logging.getLogger(__name__ + '.__init__')
+SLIMCHARS = 'fiíIÍjlĺľrtť.,;/ ()|"\'!:\\'
+
class ServiceItemContext(object):
"""
@@ -327,7 +328,6 @@ def expand_and_align_chords_in_line(match):
:param match:
:return: The line with expanded html-chords
"""
- SLIMCHARS = 'fiíIÍjlĺľrtť.,;/ ()|"\'!:\\'
whitespaces = ''
chordlen = 0
taillen = 0
@@ -389,7 +389,8 @@ def expand_and_align_chords_in_line(match):
ws_right = ws_left = ' ' * wsl_mod
whitespaces = ws_left + '–' + ws_right
whitespaces = '' + whitespaces + ''
- return '' + chord + '' + tail + whitespaces + remainder
+ return '' + html.escape(chord) + '' + html.escape(tail) + \
+ whitespaces + html.escape(remainder)
def expand_chords(text):
@@ -417,7 +418,7 @@ def expand_chords(text):
expanded_text_lines.append(new_line)
else:
chords_on_prev_line = False
- expanded_text_lines.append(line)
+ expanded_text_lines.append(html.escape(line))
return '{br}'.join(expanded_text_lines)
@@ -429,7 +430,6 @@ def compare_chord_lyric(chord, lyric):
:param lyric:
:return:
"""
- SLIMCHARS = 'fiíIÍjlĺľrtť.,;/ ()|"\'!:\\'
chordlen = 0
if chord == ' ':
return 0
diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py
index 7068496f0..c8040aa58 100644
--- a/openlp/core/lib/serviceitem.py
+++ b/openlp/core/lib/serviceitem.py
@@ -261,7 +261,7 @@ class ServiceItem(RegistryProperties):
previous_pages[verse_tag] = (slide['raw_slide'], pages)
for page in pages:
page = page.replace('
', '{br}')
- html_data = expand_tags(html.escape(page.rstrip()), expand_chord_tags)
+ html_data = expand_tags(page.rstrip(), expand_chord_tags)
new_frame = {
'title': clean_tags(page),
'text': clean_tags(page.rstrip(), expand_chord_tags),
diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py
index 3c7378dca..77f093625 100644
--- a/tests/functional/openlp_core_lib/test_lib.py
+++ b/tests/functional/openlp_core_lib/test_lib.py
@@ -764,6 +764,23 @@ class TestLib(TestCase):
' G'
self.assertEqual(expected_html, text_with_expanded_chords, 'The expanded chords should look as expected!')
+ def test_expand_chords2(self):
+ """
+ Test that the expanding of chords works as expected when special chars are involved.
+ """
+ import html
+ # GIVEN: A lyrics-line with chords
+ text_with_chords = "I[D]'M NOT MOVED BY WHAT I SEE HALLE[F]LUJA[C]H"
+
+ # WHEN: Expanding the chords
+ text_with_expanded_chords = expand_tags(text_with_chords, True)
+
+ # THEN: We should get html that looks like below
+ expected_html = 'ID' \
+ ''M NOT MOVED BY WHAT I SEE HALLEF' \
+ 'LUJACH'
+ self.assertEqual(expected_html, text_with_expanded_chords, 'The expanded chords should look as expected!')
+
def test_compare_chord_lyric_short_chord(self):
"""
Test that the chord/lyric comparing works.
diff --git a/tests/functional/openlp_plugins/songs/test_lib.py b/tests/functional/openlp_plugins/songs/test_lib.py
index d1cb22908..334282a44 100644
--- a/tests/functional/openlp_plugins/songs/test_lib.py
+++ b/tests/functional/openlp_plugins/songs/test_lib.py
@@ -206,7 +206,7 @@ class TestLib(TestCase):
assert result[0][3] == 0, 'The start indices should be kept.'
assert result[0][4] == 21, 'The stop indices should be kept.'
- def test_remove_typos_beginning_negated(self):
+ def test_remove_typos_middle_negated(self):
"""
Test the _remove_typos function with a large difference in the middle.
"""