From 064a005ce32fc23470784ab68d2e7519b30ae892 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 18 Nov 2013 23:19:53 +0100 Subject: [PATCH] mpd: Ensure quotes are matched --- .../mpd/protocol/current_playlist.py | 9 +++---- mopidy/frontends/mpd/protocol/music_db.py | 14 ++++++----- mopidy/frontends/mpd/protocol/playback.py | 24 +++++++------------ .../mpd/protocol/stored_playlists.py | 6 ++--- 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index c514538c..c64ee9df 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -180,8 +180,7 @@ def playlist(context): return playlistinfo(context) -@handle_request(r'playlistfind\ (?P[^"]+)\ "(?P[^"]+)"$') -@handle_request(r'playlistfind\ "(?P[^"]+)"\ "(?P[^"]+)"$') +@handle_request(r'playlistfind\ ("?)(?P[^"]+)\1\ "(?P[^"]+)"$') def playlistfind(context, tag, needle): """ *musicpd.org, current playlist section:* @@ -263,8 +262,7 @@ def playlistinfo(context, songpos=None, start=None, end=None): return translator.tracks_to_mpd_format(tl_tracks, start, end) -@handle_request(r'playlistsearch\ "(?P[^"]+)"\ "(?P[^"]+)"$') -@handle_request(r'playlistsearch\ (?P\w+)\ "(?P[^"]+)"$') +@handle_request(r'playlistsearch\ ("?)(?P\w+)\1\ "(?P[^"]+)"$') def playlistsearch(context, tag, needle): """ *musicpd.org, current playlist section:* @@ -282,8 +280,7 @@ def playlistsearch(context, tag, needle): raise MpdNotImplemented # TODO -@handle_request(r'plchanges\ (?P-?\d+)$') -@handle_request(r'plchanges\ "(?P-?\d+)"$') +@handle_request(r'plchanges\ ("?)(?P-?\d+)\1$') def plchanges(context, version): """ *musicpd.org, current playlist section:* diff --git a/mopidy/frontends/mpd/protocol/music_db.py b/mopidy/frontends/mpd/protocol/music_db.py index 94f22be1..457e90de 100644 --- a/mopidy/frontends/mpd/protocol/music_db.py +++ b/mopidy/frontends/mpd/protocol/music_db.py @@ -11,7 +11,7 @@ from mopidy.frontends.mpd.protocol import handle_request, stored_playlists LIST_QUERY = r""" - "? # Optional quote around the field type + ("?) # Optional quote around the field type (?P( # Field to list in the response [Aa]rtist | [Aa]lbumartist @@ -21,7 +21,7 @@ LIST_QUERY = r""" | [Gg]enre | [Pp]erformer )) - "? # End of optional quote around the field type + \1 # End of optional quote around the field type (?: # Non-capturing group for optional search query \ # A single space (?P.*) @@ -47,10 +47,10 @@ SEARCH_FIELDS = r""" SEARCH_QUERY = r""" (?P - ( + (?: # Non-capturing group for repeating query pairs "? # Optional quote around the field type (?: -""" + SEARCH_FIELDS + """ +""" + SEARCH_FIELDS + r""" ) "? # End of optional quote around the field type \ # A single space @@ -454,7 +454,8 @@ def lsinfo(context, uri=None): raise MpdNotImplemented # TODO -@handle_request(r'rescan(\ "(?P[^"]+)")*$') +@handle_request(r'rescan$') +@handle_request(r'rescan\ "(?P[^"]+)"$') def rescan(context, uri=None): """ *musicpd.org, music database section:* @@ -555,7 +556,8 @@ def searchaddpl(context, playlist_name, mpd_query): context.core.playlists.save(playlist) -@handle_request(r'update(\ "(?P[^"]+)")*$') +@handle_request(r'update$') +@handle_request(r'update\ "(?P[^"]+)"$') def update(context, uri=None, rescan_unmodified_files=False): """ *musicpd.org, music database section:* diff --git a/mopidy/frontends/mpd/protocol/playback.py b/mopidy/frontends/mpd/protocol/playback.py index 28772dde..27ee6d4b 100644 --- a/mopidy/frontends/mpd/protocol/playback.py +++ b/mopidy/frontends/mpd/protocol/playback.py @@ -6,8 +6,7 @@ from mopidy.frontends.mpd.exceptions import ( MpdArgError, MpdNoExistError, MpdNotImplemented) -@handle_request(r'consume\ (?P[01])$') -@handle_request(r'consume\ "(?P[01])"$') +@handle_request(r'consume\ ("?)(?P[01])\1$') def consume(context, state): """ *musicpd.org, playback section:* @@ -129,8 +128,7 @@ def play(context): return context.core.playback.play().get() -@handle_request(r'playid\ (?P-?\d+)$') -@handle_request(r'playid\ "(?P-?\d+)"$') +@handle_request(r'playid\ ("?)(?P-?\d+)\1$') def playid(context, tlid): """ *musicpd.org, playback section:* @@ -157,8 +155,7 @@ def playid(context, tlid): return context.core.playback.play(tl_tracks[0]).get() -@handle_request(r'play\ (?P-?\d+)$') -@handle_request(r'play\ "(?P-?\d+)"$') +@handle_request(r'play\ ("?)(?P-?\d+)\1$') def playpos(context, songpos): """ *musicpd.org, playback section:* @@ -252,8 +249,7 @@ def previous(context): return context.core.playback.previous().get() -@handle_request(r'random\ (?P[01])$') -@handle_request(r'random\ "(?P[01])"$') +@handle_request(r'random\ ("?)(?P[01])\1$') def random(context, state): """ *musicpd.org, playback section:* @@ -268,8 +264,7 @@ def random(context, state): context.core.tracklist.random = False -@handle_request(r'repeat\ (?P[01])$') -@handle_request(r'repeat\ "(?P[01])"$') +@handle_request(r'repeat\ ("?)(?P[01])\1$') def repeat(context, state): """ *musicpd.org, playback section:* @@ -314,8 +309,7 @@ def replay_gain_status(context): return 'off' # TODO -@handle_request(r'seek\ (?P\d+)\ (?P\d+)$') -@handle_request(r'seek\ "(?P\d+)"\ "(?P\d+)"$') +@handle_request(r'seek\ ("?)(?P\d+)\1\ ("?)(?P\d+)\3$') def seek(context, songpos, seconds): """ *musicpd.org, playback section:* @@ -370,8 +364,7 @@ def seekcur(context, position=None, diff=None): context.core.playback.seek(position).get() -@handle_request(r'setvol\ (?P[-+]*\d+)$') -@handle_request(r'setvol\ "(?P[-+]*\d+)"$') +@handle_request(r'setvol\ ("?)(?P[-+]*\d+)\1$') def setvol(context, volume): """ *musicpd.org, playback section:* @@ -392,8 +385,7 @@ def setvol(context, volume): context.core.playback.volume = volume -@handle_request(r'single\ (?P[01])$') -@handle_request(r'single\ "(?P[01])"$') +@handle_request(r'single\ ("?)(?P[01])\1$') def single(context, state): """ *musicpd.org, playback section:* diff --git a/mopidy/frontends/mpd/protocol/stored_playlists.py b/mopidy/frontends/mpd/protocol/stored_playlists.py index 1ac12864..974dbc7f 100644 --- a/mopidy/frontends/mpd/protocol/stored_playlists.py +++ b/mopidy/frontends/mpd/protocol/stored_playlists.py @@ -7,8 +7,7 @@ from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.translator import playlist_to_mpd_format -@handle_request(r'listplaylist\ (?P\w+)$') -@handle_request(r'listplaylist\ "(?P[^"]+)"$') +@handle_request(r'listplaylist\ ("?)(?P[^"]+)\1$') def listplaylist(context, name): """ *musicpd.org, stored playlists section:* @@ -29,8 +28,7 @@ def listplaylist(context, name): return ['file: %s' % t.uri for t in playlist.tracks] -@handle_request(r'listplaylistinfo\ (?P\w+)$') -@handle_request(r'listplaylistinfo\ "(?P[^"]+)"$') +@handle_request(r'listplaylistinfo\ ("?)(?P[^"]+)\1$') def listplaylistinfo(context, name): """ *musicpd.org, stored playlists section:*