Merge pull request #486 from alzeih/develop
Strip invalid characters from playlist names sent through MPD frontend Fix #474 Fix #480
This commit is contained in:
commit
091f8ffdf0
@ -236,6 +236,8 @@ class MpdContext(object):
|
||||
#: The subsytems that we want to be notified about in idle mode.
|
||||
subscriptions = None
|
||||
|
||||
_invalid_playlist_chars = re.compile(r'[\n\r/]')
|
||||
|
||||
def __init__(self, dispatcher, session=None, config=None, core=None):
|
||||
self.dispatcher = dispatcher
|
||||
self.session = session
|
||||
@ -248,10 +250,11 @@ class MpdContext(object):
|
||||
self.refresh_playlists_mapping()
|
||||
|
||||
def create_unique_name(self, playlist_name):
|
||||
name = playlist_name
|
||||
stripped_name = self._invalid_playlist_chars.sub(' ', playlist_name)
|
||||
name = stripped_name
|
||||
i = 2
|
||||
while name in self._playlist_uri_from_name:
|
||||
name = '%s [%d]' % (playlist_name, i)
|
||||
name = '%s [%d]' % (stripped_name, i)
|
||||
i += 1
|
||||
return name
|
||||
|
||||
|
||||
@ -107,6 +107,30 @@ class PlaylistsHandlerTest(protocol.BaseTestCase):
|
||||
self.assertNotInResponse('playlist: ')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_listplaylists_replaces_newline_with_space(self):
|
||||
self.backend.playlists.playlists = [
|
||||
Playlist(name='a\n', uri='dummy:')]
|
||||
self.sendRequest('listplaylists')
|
||||
self.assertInResponse('playlist: a ')
|
||||
self.assertNotInResponse('playlist: a\n')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_listplaylists_replaces_carriage_return_with_space(self):
|
||||
self.backend.playlists.playlists = [
|
||||
Playlist(name='a\r', uri='dummy:')]
|
||||
self.sendRequest('listplaylists')
|
||||
self.assertInResponse('playlist: a ')
|
||||
self.assertNotInResponse('playlist: a\r')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_listplaylists_replaces_forward_slash_with_space(self):
|
||||
self.backend.playlists.playlists = [
|
||||
Playlist(name='a/', uri='dummy:')]
|
||||
self.sendRequest('listplaylists')
|
||||
self.assertInResponse('playlist: a ')
|
||||
self.assertNotInResponse('playlist: a/')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_load_appends_to_tracklist(self):
|
||||
self.core.tracklist.add([Track(uri='a'), Track(uri='b')])
|
||||
self.assertEqual(len(self.core.tracklist.tracks.get()), 2)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user