CharField: Cover handling of surrogate characters

This commit is contained in:
Sebastian Pipping 2019-11-23 22:04:14 +01:00
parent 4607c8a866
commit 2a3d3550aa

View File

@ -759,6 +759,21 @@ class TestCharField(FieldValues):
'Null characters are not allowed.'
]
def test_surrogate_characters(self):
field = serializers.CharField()
for code_point, expected_message in (
(0xD800, 'Surrogate characters are not allowed: U+D800.'),
(0xDFFF, 'Surrogate characters are not allowed: U+DFFF.'),
):
with pytest.raises(serializers.ValidationError) as exc_info:
field.run_validation(chr(code_point))
assert exc_info.value.detail[0].code == 'surrogate_characters_not_allowed'
assert str(exc_info.value.detail[0]) == expected_message
for code_point in (0xD800 - 1, 0xDFFF + 1):
field.run_validation(chr(code_point))
def test_iterable_validators(self):
"""
Ensure `validators` parameter is compatible with reasonable iterables.