1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #26672 -- Fixed HStoreField to raise ValidationError instead of crashing on non-dict JSON input.

This commit is contained in:
Brad Melin
2016-05-29 14:17:07 +02:00
committed by Tim Graham
parent abc5223834
commit f6517a5335
4 changed files with 22 additions and 1 deletions

View File

@@ -208,6 +208,13 @@ class TestFormField(PostgreSQLTestCase):
self.assertEqual(cm.exception.messages[0], 'Could not load JSON data.')
self.assertEqual(cm.exception.code, 'invalid_json')
def test_non_dict_json(self):
field = forms.HStoreField()
msg = 'Input must be a JSON dictionary.'
with self.assertRaisesMessage(exceptions.ValidationError, msg) as cm:
field.clean('["a", "b", 1]')
self.assertEqual(cm.exception.code, 'invalid_format')
def test_not_string_values(self):
field = forms.HStoreField()
value = field.clean('{"a": 1}')