mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
fixed handling of ID3 frames with empty lists
--HG-- extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%40218
This commit is contained in:
parent
155544dbac
commit
895806e8cc
3 changed files with 21 additions and 1 deletions
|
|
@ -225,9 +225,13 @@ class MediaField(object):
|
||||||
|
|
||||||
# possibly index the list
|
# possibly index the list
|
||||||
if style.list_elem:
|
if style.list_elem:
|
||||||
return entry[0]
|
if entry: # List must have at least one value.
|
||||||
|
return entry[0]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
except KeyError: # the tag isn't present
|
except KeyError: # the tag isn't present
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
BIN
test/rsrc/emptylist.mp3
Normal file
BIN
test/rsrc/emptylist.mp3
Normal file
Binary file not shown.
|
|
@ -222,6 +222,19 @@ def suite_for_file(path, correct_dict, writing=True):
|
||||||
s.addTest(MakeWritingTest(path, correct_dict, field)())
|
s.addTest(MakeWritingTest(path, correct_dict, field)())
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
class EdgeTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.emptylist = beets.mediafile.MediaFile(
|
||||||
|
os.path.join('rsrc', 'emptylist.mp3'))
|
||||||
|
|
||||||
|
def test_emptylist(self):
|
||||||
|
# Some files have an ID3 frame that has a list with no elements.
|
||||||
|
# This is very hard to produce, so this is just the first 8192
|
||||||
|
# bytes of a file found "in the wild".
|
||||||
|
genre = self.emptylist.genre
|
||||||
|
self.assertEqual(genre, '')
|
||||||
|
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
s = unittest.TestSuite()
|
s = unittest.TestSuite()
|
||||||
|
|
||||||
|
|
@ -250,6 +263,9 @@ def suite():
|
||||||
path = os.path.join('rsrc', fname)
|
path = os.path.join('rsrc', fname)
|
||||||
for field, value in correct_dict.iteritems():
|
for field, value in correct_dict.iteritems():
|
||||||
s.addTest(MakeReadOnlyTest(path, field, value)())
|
s.addTest(MakeReadOnlyTest(path, field, value)())
|
||||||
|
|
||||||
|
# Edge cases.
|
||||||
|
s.addTest(EdgeTest('test_emptylist'))
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue