diff --git a/beets/dbcore/queryparse.py b/beets/dbcore/queryparse.py index 782037e3c..89b7bd64a 100644 --- a/beets/dbcore/queryparse.py +++ b/beets/dbcore/queryparse.py @@ -188,7 +188,11 @@ def parse_sorted_query(model_cls, parts, prefixes={}): )) del subquery_parts[:] else: - if part.endswith((u'+', u'-')) and u':' not in part: + # Sort parts (1) end in + or -, (2) don't have a field, and + # (3) consist of more than just the + or -. + if part.endswith((u'+', u'-')) \ + and u':' not in part \ + and len(part) > 1: sort_parts.append(part) else: subquery_parts.append(part) diff --git a/docs/changelog.rst b/docs/changelog.rst index 9627fb1bb..0039bb969 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -47,6 +47,8 @@ Fixes: encounters an error. :bug:`1592` * Case-insensitive path queries might have returned nothing because of a wrong SQL query. +* Fix a crash when a query contains a "+" or "-" alone in a component. + :bug:`1605` 1.3.14 (August 2, 2015) diff --git a/test/test_dbcore.py b/test/test_dbcore.py index 313530764..6fc07d0f6 100644 --- a/test/test_dbcore.py +++ b/test/test_dbcore.py @@ -518,6 +518,12 @@ class ParseSortedQueryTest(unittest.TestCase): self.assertIsInstance(s, dbcore.query.NullSort) self.assertEqual(len(q.subqueries), 3) + def test_only_direction(self): + q, s = self.psq('-') + self.assertIsInstance(q, dbcore.query.AndQuery) + self.assertIsInstance(s, dbcore.query.NullSort) + self.assertEqual(len(q.subqueries), 1) + class ResultsIteratorTest(unittest.TestCase): def setUp(self):