Skip to content

Commit

Permalink
Fix #1896 (bungled fix to #1895)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsyo committed Feb 28, 2016
1 parent 5b5a8c5 commit 48659c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions beets/mediafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ def _sc_decode(soundcheck):
used by ReplayGain.
"""
# We decode binary data. If one of the formats gives us a text
# string, guess that it's UTF-8.
# string, interpret it as UTF-8.
if isinstance(soundcheck, unicode):
soundcheck = soundcheck.decode('utf8')
soundcheck = soundcheck.encode('utf8')

# SoundCheck tags consist of 10 numbers, each represented by 8
# characters of ASCII hex preceded by a space.
Expand Down
7 changes: 7 additions & 0 deletions test/test_mediafile_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ def test_special_characters(self):
self.assertEqual(gain, 0.0)
self.assertEqual(peak, 0.0)

def test_decode_handles_unicode(self):
# Most of the time, we expect to decode the raw bytes. But some formats
# might give us text strings, which we need to handle.
gain, peak = beets.mediafile._sc_decode(u'caf\xe9')
self.assertEqual(gain, 0.0)
self.assertEqual(peak, 0.0)


class ID3v23Test(unittest.TestCase, TestHelper):
def _make_test(self, ext='mp3', id3v23=False):
Expand Down

0 comments on commit 48659c5

Please sign in to comment.