diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index a7682dab1..2e72e05ca 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -203,6 +203,10 @@ def order_items(items, trackinfo): information. This always produces a result if the numbers of tracks match. """ + # Make sure lengths match. + if len(items) != len(trackinfo): + return None + # Construct the cost matrix. costs = [] for cur_item in items: diff --git a/test/test_autotag.py b/test/test_autotag.py index e7463c700..856f22b1b 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -111,6 +111,15 @@ class OrderingTest(unittest.TestCase): self.assertEqual(ordered[1].title, 'two') self.assertEqual(ordered[2].title, 'three') + def test_order_returns_none_for_length_mismatch(self): + items = [] + items.append(self.item('one', 1)) + items.append(self.item('two', 2)) + trackinfo = [] + trackinfo.append({'title': 'one', 'track': 1}) + ordered = autotag.order_items(items, trackinfo) + self.assertEqual(ordered, None) + class ApplyTest(unittest.TestCase): def setUp(self): self.items = []