Fix for bug 952533

This commit is contained in:
Philip Ridout 2012-03-22 06:50:54 +00:00
parent 50f3f2c9b8
commit 1fd08401bf
2 changed files with 17 additions and 4 deletions

View File

@ -53,6 +53,8 @@ APPLICATION_VERSION = {}
IMAGES_FILTER = None IMAGES_FILTER = None
UNO_CONNECTION_TYPE = u'pipe' UNO_CONNECTION_TYPE = u'pipe'
#UNO_CONNECTION_TYPE = u'socket' #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]+))?') VERSION_SPLITTER = re.compile(r'([0-9]+).([0-9]+).([0-9]+)(?:-bzr([0-9]+))?')
class VersionThread(QtCore.QThread): class VersionThread(QtCore.QThread):
@ -400,7 +402,7 @@ def clean_filename(filename):
""" """
if not isinstance(filename, unicode): if not isinstance(filename, unicode):
filename = unicode(filename, u'utf-8') 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): def delete_file(file_path_name):
""" """

View File

@ -257,6 +257,13 @@ def clean_string(string):
""" """
return WHITESPACE.sub(u' ', APOSTROPHE.sub(u'', string)).lower() 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 re.sub(u'[\x00-\x1F\x7F-\x9F]| +$', u'', title, re.UNICODE)
def clean_song(manager, song): def clean_song(manager, song):
""" """
Cleans the search title, rebuilds the search lyrics, adds a default author Cleans the search title, rebuilds the search lyrics, adds a default author
@ -275,10 +282,14 @@ def clean_song(manager, song):
song.alternate_title = unicode(song.alternate_title) song.alternate_title = unicode(song.alternate_title)
if isinstance(song.lyrics, buffer): if isinstance(song.lyrics, buffer):
song.lyrics = unicode(song.lyrics) song.lyrics = unicode(song.lyrics)
song.title = song.title.rstrip() if song.title else u'' if song.title:
if song.alternate_title is None: 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 = u''
song.alternate_title = song.alternate_title.strip()
song.search_title = clean_string(song.title) + u'@' + \ song.search_title = clean_string(song.title) + u'@' + \
clean_string(song.alternate_title) clean_string(song.alternate_title)
# Only do this, if we the song is a 1.9.4 song (or older). # Only do this, if we the song is a 1.9.4 song (or older).