phill has proposed merging lp:~phill-ridout/openlp/bug952533 into lp:openlp.
Requested reviews: Jonathan Corwin (j-corwin) Meinert Jordan (m2j) Related bugs: Bug #952533 in OpenLP: "Invalid file name characters in song name causes OpenLyrics to crash " https://bugs.launchpad.net/openlp/+bug/952533 For more details, see: https://code.launchpad.net/~phill-ridout/openlp/bug952533/+merge/98922 -- https://code.launchpad.net/~phill-ridout/openlp/bug952533/+merge/98922 Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/utils/__init__.py' --- openlp/core/utils/__init__.py 2012-02-27 18:41:24 +0000 +++ openlp/core/utils/__init__.py 2012-03-22 20:42:19 +0000 @@ -53,6 +53,8 @@ IMAGES_FILTER = None UNO_CONNECTION_TYPE = u'pipe' #UNO_CONNECTION_TYPE = u'socket' +CONTROL_CHARS = re.compile(u'[\x00-\x1F\x7F-\x9F]', re.UNICODE) +INVALID_FILE_CHARS = re.compile(u'[\\\/:\*\?"<>\|\+\[\]%]', re.UNICODE) VERSION_SPLITTER = re.compile(r'([0-9]+).([0-9]+).([0-9]+)(?:-bzr([0-9]+))?') class VersionThread(QtCore.QThread): @@ -400,7 +402,7 @@ """ if not isinstance(filename, unicode): filename = unicode(filename, u'utf-8') - return re.sub(r'[/\\?*|<>\[\]":<>+%\n]+', u'_', filename).strip(u'_') + return INVALID_FILE_CHARS.sub(u'_', CONTROL_CHARS.sub(u'', filename)) def delete_file(file_path_name): """ === modified file 'openlp/plugins/songs/lib/__init__.py' --- openlp/plugins/songs/lib/__init__.py 2011-12-27 10:33:55 +0000 +++ openlp/plugins/songs/lib/__init__.py 2012-03-22 20:42:19 +0000 @@ -29,6 +29,7 @@ from PyQt4 import QtGui from openlp.core.lib import translate +from openlp.core.utils import CONTROL_CHARS from db import Author from ui import SongStrings @@ -256,6 +257,13 @@ Strips punctuation from the passed string to assist searching """ return WHITESPACE.sub(u' ', APOSTROPHE.sub(u'', string)).lower() + +def clean_title(title): + """ + Cleans the song title by removing Unicode control chars groups C0 & C1, + as well as any trailing spaces + """ + return CONTROL_CHARS.sub(u'', title).rstrip() def clean_song(manager, song): """ @@ -275,10 +283,14 @@ song.alternate_title = unicode(song.alternate_title) if isinstance(song.lyrics, buffer): song.lyrics = unicode(song.lyrics) - song.title = song.title.rstrip() if song.title else u'' - if song.alternate_title is None: + if song.title: + song.title = clean_title(song.title) + else: + song.title = u'' + if song.alternate_title: + song.alternate_title = clean_title(song.alternate_title) + else: song.alternate_title = u'' - song.alternate_title = song.alternate_title.strip() song.search_title = clean_string(song.title) + u'@' + \ clean_string(song.alternate_title) # Only do this, if we the song is a 1.9.4 song (or older).
_______________________________________________ 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