Skip to content

Commit

Permalink
local: Fix crash on non-ASCII chars in URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jodal committed Oct 24, 2013
1 parent e448d77 commit b0ae7d3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ of the following extensions as well:
e.g. HTTP radio streams and not just ``local:track:...`` URIs. This used to
work, but was broken in Mopidy 0.15.0. (Fixes: :issue:`527`)

- Fixed crash when playing ``local:track:...`` URIs which contained non-ASCII
chars after uridecode.

**MPD frontend**

- Made the formerly unused commands ``outputs``, ``enableoutput``, and
Expand Down
2 changes: 1 addition & 1 deletion mopidy/backends/local/playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LocalPlaybackProvider(base.BasePlaybackProvider):
def change_track(self, track):
media_dir = self.backend.config['local']['media_dir']
# TODO: check that type is correct.
file_path = path.uri_to_path(track.uri).split(':', 1)[1]
file_path = path.uri_to_path(track.uri).split(b':', 1)[1]
file_path = os.path.join(media_dir, file_path)
track = track.copy(uri=path.path_to_uri(file_path))
return super(LocalPlaybackProvider, self).change_track(track)
8 changes: 8 additions & 0 deletions tests/backends/local/playback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def test_play_flac(self):
self.playback.play()
self.assertEqual(self.playback.state, PlaybackState.PLAYING)

def test_play_uri_with_non_ascii_bytes(self):
# Regression test: If trying to do .split(u':') on a bytestring, the
# string will be decoded from ASCII to Unicode, which will crash on
# non-ASCII strings, like the bytestring the following URI decodes to.
self.add_track('local:track:12%20Doin%E2%80%99%20It%20Right.flac')
self.playback.play()
self.assertEqual(self.playback.state, PlaybackState.PLAYING)

def test_initial_state_is_stopped(self):
self.assertEqual(self.playback.state, PlaybackState.STOPPED)

Expand Down

0 comments on commit b0ae7d3

Please sign in to comment.