Added test for filtering JSONField key transforms with quoted strings.

This commit is contained in:
Mariusz Felisiak 2020-11-20 07:25:32 +01:00
parent fecfec6deb
commit bec415b290
1 changed files with 7 additions and 0 deletions

View File

@ -276,6 +276,7 @@ class TestQuerying(TestCase):
'j': None, 'j': None,
'k': {'l': 'm'}, 'k': {'l': 'm'},
'n': [None], 'n': [None],
'o': '"quoted"',
}, },
[1, [2]], [1, [2]],
{'k': True, 'l': False, 'foo': 'bax'}, {'k': True, 'l': False, 'foo': 'bax'},
@ -774,6 +775,12 @@ class TestQuerying(TestCase):
def test_key_iregex(self): def test_key_iregex(self):
self.assertIs(NullableJSONModel.objects.filter(value__foo__iregex=r'^bAr$').exists(), True) self.assertIs(NullableJSONModel.objects.filter(value__foo__iregex=r'^bAr$').exists(), True)
def test_key_quoted_string(self):
self.assertEqual(
NullableJSONModel.objects.filter(value__o='"quoted"').get(),
self.objs[4],
)
@skipUnlessDBFeature('has_json_operators') @skipUnlessDBFeature('has_json_operators')
def test_key_sql_injection(self): def test_key_sql_injection(self):
with CaptureQueriesContext(connection) as queries: with CaptureQueriesContext(connection) as queries: