From 6c7566a2f3460ef6fcc24ab842dd0d0cf8c1ebe0 Mon Sep 17 00:00:00 2001 From: alzeih Date: Tue, 30 Jul 2013 13:57:29 +1200 Subject: [PATCH] Strip invalid characters from playlist names for MPD frontend Fixes mopidy/mopidy$480 and mopidy/mopidy#474 --- mopidy/frontends/mpd/dispatcher.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mopidy/frontends/mpd/dispatcher.py b/mopidy/frontends/mpd/dispatcher.py index 6590897d..7a4ee7d7 100644 --- a/mopidy/frontends/mpd/dispatcher.py +++ b/mopidy/frontends/mpd/dispatcher.py @@ -236,6 +236,9 @@ class MpdContext(object): #: The subsytems that we want to be notified about in idle mode. subscriptions = None + #regex for invalid characters in playlist names + _invalid_playlist_chars = re.compile(r'[\n\t\\/]') + def __init__(self, dispatcher, session=None, config=None, core=None): self.dispatcher = dispatcher self.session = session @@ -248,10 +251,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