Fix #1896 (bungled fix to #1895)

This commit is contained in:
Adrian Sampson 2016-02-28 13:37:01 -08:00
parent 5b5a8c5a6d
commit 48659c5df4
2 changed files with 9 additions and 2 deletions

View file

@ -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.

View file

@ -313,6 +313,13 @@ class SoundCheckTest(unittest.TestCase):
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):