Merge lp:~googol-deactivatedaccount/openlp/bug-863376 into lp:openlp

Proposed by Andreas Preikschat
Status: Merged
Merged at revision: 1774
Proposed branch: lp:~googol-deactivatedaccount/openlp/bug-863376
Merge into: lp:openlp
Diff against target: 108 lines (+23/-22)
1 file modified
openlp/plugins/songs/lib/xml.py (+23/-22)
To merge this branch: bzr merge lp:~googol-deactivatedaccount/openlp/bug-863376
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Review via email: mp+78778@code.launchpad.net

This proposal supersedes a proposal from 2011-10-08.

Commit message

- fixed bug 863376 ('<' in song lyrics causes a traceback)
- clean ups

Description of the change

Hello,

- fixed bug 863376 ("<" in song lyrics causes a traceback) (See line 32)
- clean ups

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

What happens if you add a song with "&" in it?

Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

Comments should be on a separate line 17,18
Line 95 u'<lines>' + text + u'</lines>' should be u'<lines>%s</lines>' % text ??????????

review: Needs Fixing
Revision history for this message
Andreas Preikschat (googol-deactivatedaccount) wrote : Posted in a previous version of this proposal

> What happens if you add a song with "&" in it?

All critical characters are escaped:
>>> import cgi
>>> cgi.escape(u'aaa < bbb > ccc & ddd')
u'aaa &lt; bbb &gt; ccc &amp; ddd'

Revision history for this message
Tim Bentley (trb143) :
review: Approve
Revision history for this message
Andreas Preikschat (googol-deactivatedaccount) wrote :

I assume you forgot to set it to "Approved". However, I am merging it now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/plugins/songs/lib/xml.py'
--- openlp/plugins/songs/lib/xml.py 2011-09-23 00:12:55 +0000
+++ openlp/plugins/songs/lib/xml.py 2011-10-09 19:56:25 +0000
@@ -60,7 +60,7 @@
60 </lyrics>60 </lyrics>
61 </song>61 </song>
62"""62"""
6363import cgi
64import logging64import logging
65import re65import re
6666
@@ -257,11 +257,12 @@
257257
258 """258 """
259 IMPLEMENTED_VERSION = u'0.8'259 IMPLEMENTED_VERSION = u'0.8'
260 START_TAGS_REGEX = re.compile(r'\{(\w+)\}')
261 END_TAGS_REGEX = re.compile(r'\{\/(\w+)\}')
262 VERSE_NUMBER_REGEX = re.compile(u'[a-zA-Z]*')
260263
261 def __init__(self, manager):264 def __init__(self, manager):
262 self.manager = manager265 self.manager = manager
263 self.start_tags_regex = re.compile(r'\{(\w+)\}') # {abc} -> abc
264 self.end_tags_regex = re.compile(r'\{\/(\w+)\}') # {/abc} -> abc
265266
266 def song_to_xml(self, song):267 def song_to_xml(self, song):
267 """268 """
@@ -334,7 +335,8 @@
334 if u'lang' in verse[0]:335 if u'lang' in verse[0]:
335 verse_element.set(u'lang', verse[0][u'lang'])336 verse_element.set(u'lang', verse[0][u'lang'])
336 # Create a list with all "virtual" verses.337 # Create a list with all "virtual" verses.
337 virtual_verses = verse[1].split(u'[---]')338 virtual_verses = cgi.escape(verse[1])
339 virtual_verses = virtual_verses.split(u'[---]')
338 for index, virtual_verse in enumerate(virtual_verses):340 for index, virtual_verse in enumerate(virtual_verses):
339 # Add formatting tags to text341 # Add formatting tags to text
340 lines_element = self._add_text_with_tags_to_lines(verse_element,342 lines_element = self._add_text_with_tags_to_lines(verse_element,
@@ -402,32 +404,32 @@
402404
403 def _add_tag_to_formatting(self, tag_name, tags_element):405 def _add_tag_to_formatting(self, tag_name, tags_element):
404 """406 """
405 Add new formatting tag to the element ``<format>``407 Add new formatting tag to the element ``<format>`` if the tag is not
406 if the tag is not present yet.408 present yet.
407 """409 """
408 available_tags = FormattingTags.get_html_tags()410 available_tags = FormattingTags.get_html_tags()
409 start_tag = '{%s}' % tag_name411 start_tag = '{%s}' % tag_name
410 for t in available_tags:412 for tag in available_tags:
411 if t[u'start tag'] == start_tag:413 if tag[u'start tag'] == start_tag:
412 # Create new formatting tag in openlyrics xml.414 # Create new formatting tag in openlyrics xml.
413 el = self._add_text_to_element(u'tag', tags_element)415 element = self._add_text_to_element(u'tag', tags_element)
414 el.set(u'name', tag_name)416 element.set(u'name', tag_name)
415 el_open = self._add_text_to_element(u'open', el)417 element_open = self._add_text_to_element(u'open', element)
416 el_open.text = etree.CDATA(t[u'start html'])418 element_open.text = etree.CDATA(tag[u'start html'])
417 # Check if formatting tag contains end tag. Some formatting419 # Check if formatting tag contains end tag. Some formatting
418 # tags e.g. {br} has only start tag. If no end tag is present420 # tags e.g. {br} has only start tag. If no end tag is present
419 # <close> element has not to be in OpenLyrics xml.421 # <close> element has not to be in OpenLyrics xml.
420 if t['end tag']:422 if tag['end tag']:
421 el_close = self._add_text_to_element(u'close', el)423 element_close = self._add_text_to_element(u'close', element)
422 el_close.text = etree.CDATA(t[u'end html'])424 element_close.text = etree.CDATA(tag[u'end html'])
423425
424 def _add_text_with_tags_to_lines(self, verse_element, text, tags_element):426 def _add_text_with_tags_to_lines(self, verse_element, text, tags_element):
425 """427 """
426 Convert text with formatting tags from OpenLP format to OpenLyrics428 Convert text with formatting tags from OpenLP format to OpenLyrics
427 format and append it to element ``<lines>``.429 format and append it to element ``<lines>``.
428 """430 """
429 start_tags = self.start_tags_regex.findall(text)431 start_tags = OpenLyrics.START_TAGS_REGEX.findall(text)
430 end_tags = self.end_tags_regex.findall(text)432 end_tags = OpenLyrics.END_TAGS_REGEX.findall(text)
431 # Replace start tags with xml syntax.433 # Replace start tags with xml syntax.
432 for tag in start_tags:434 for tag in start_tags:
433 # Tags already converted to xml structure.435 # Tags already converted to xml structure.
@@ -442,12 +444,11 @@
442 if tag not in xml_tags:444 if tag not in xml_tags:
443 self._add_tag_to_formatting(tag, tags_element)445 self._add_tag_to_formatting(tag, tags_element)
444 # Replace end tags.446 # Replace end tags.
445 for t in end_tags:447 for tag in end_tags:
446 text = text.replace(u'{/%s}' % t, u'</tag>')448 text = text.replace(u'{/%s}' % tag, u'</tag>')
447 # Replace \n with <br/>.449 # Replace \n with <br/>.
448 text = text.replace(u'\n', u'<br/>')450 text = text.replace(u'\n', u'<br/>')
449 text = u'<lines>' + text + u'</lines>'451 element = etree.XML(u'<lines>%s</lines>' % text)
450 element = etree.XML(text)
451 verse_element.append(element)452 verse_element.append(element)
452 return element453 return element
453454
@@ -692,7 +693,7 @@
692 verse_tag = verse_def[0]693 verse_tag = verse_def[0]
693 else:694 else:
694 verse_tag = VerseType.Tags[VerseType.Other]695 verse_tag = VerseType.Tags[VerseType.Other]
695 verse_number = re.compile(u'[a-zA-Z]*').sub(u'', verse_def)696 verse_number = OpenLyrics.VERSE_NUMBER_REGEX.sub(u'', verse_def)
696 # OpenLyrics allows e. g. "c", but we need "c1". However, this does697 # OpenLyrics allows e. g. "c", but we need "c1". However, this does
697 # not correct the verse order.698 # not correct the verse order.
698 if not verse_number:699 if not verse_number: