forked from openlp/openlp
Fixed bug #952533: Invalid file name characters in song name causes OpenLyrics to crash.
bzr-revno: 1916 Fixes: https://launchpad.net/bugs/952533
This commit is contained in:
commit
b4e8b48c6d
@ -53,6 +53,8 @@ APPLICATION_VERSION = {}
|
||||
IMAGES_FILTER = None
|
||||
UNO_CONNECTION_TYPE = u'pipe'
|
||||
#UNO_CONNECTION_TYPE = u'socket'
|
||||
CONTROL_CHARS = re.compile(r'[\x00-\x1F\x7F-\x9F]', re.UNICODE)
|
||||
INVALID_FILE_CHARS = re.compile(r'[\\/:\*\?"<>\|\+\[\]%]', re.UNICODE)
|
||||
VERSION_SPLITTER = re.compile(r'([0-9]+).([0-9]+).([0-9]+)(?:-bzr([0-9]+))?')
|
||||
|
||||
class VersionThread(QtCore.QThread):
|
||||
@ -400,7 +402,7 @@ def clean_filename(filename):
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
|
@ -29,6 +29,7 @@ import re
|
||||
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 @@ def clean_string(string):
|
||||
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 @@ def clean_song(manager, song):
|
||||
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).
|
||||
|
Loading…
Reference in New Issue
Block a user