Handle unsafe expressions when using startswith/endswith/contains with unsafe expressions. Closes #58
This commit is contained in:
parent
2f991ac6f1
commit
7ab2e21c10
2 changed files with 10 additions and 0 deletions
|
|
@ -66,6 +66,9 @@ class StringField(BaseField):
|
|||
regex = r'%s$'
|
||||
elif op == 'exact':
|
||||
regex = r'^%s$'
|
||||
|
||||
# escape unsafe characters which could lead to a re.error
|
||||
value = re.escape(value)
|
||||
value = re.compile(regex % value, flags)
|
||||
return value
|
||||
|
||||
|
|
|
|||
|
|
@ -288,6 +288,13 @@ class QuerySetTest(unittest.TestCase):
|
|||
self.assertEqual(obj, person)
|
||||
obj = self.Person.objects(Q(name__iexact='gUIDO VAN rOSSU')).first()
|
||||
self.assertEqual(obj, None)
|
||||
|
||||
# Test unsafe expressions
|
||||
person = self.Person(name='Guido van Rossum [.\'Geek\']')
|
||||
person.save()
|
||||
|
||||
obj = self.Person.objects(Q(name__icontains='[.\'Geek')).first()
|
||||
self.assertEqual(obj, person)
|
||||
|
||||
def test_filter_chaining(self):
|
||||
"""Ensure filters can be chained together.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue