Skip to content

Commit

Permalink
Fix #1605: parsing bare + and - in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsyo committed Sep 15, 2015
1 parent 6bae814 commit f4a124e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion beets/dbcore/queryparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions test/test_dbcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,12 @@ def test_leading_comma_or_query(self):
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):
Expand Down

0 comments on commit f4a124e

Please sign in to comment.