Fix #1605: parsing bare + and - in queries

This commit is contained in:
Adrian Sampson 2015-09-15 13:53:41 -07:00
parent 6bae8146bb
commit f4a124e7e2
3 changed files with 13 additions and 1 deletions

View file

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

View file

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

View file

@ -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):