mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Added validation to UUIDField to properly catch invalid input types (lists, tuples, etc).
This commit is contained in:
parent
d2f90fd6af
commit
c153bcb479
|
@ -769,9 +769,11 @@ class UUIDField(Field):
|
|||
try:
|
||||
if isinstance(data, six.integer_types):
|
||||
return uuid.UUID(int=data)
|
||||
else:
|
||||
elif isinstance(data, six.string_types):
|
||||
return uuid.UUID(hex=data)
|
||||
except (ValueError, TypeError):
|
||||
else:
|
||||
self.fail('invalid', value=data)
|
||||
except (ValueError):
|
||||
self.fail('invalid', value=data)
|
||||
return data
|
||||
|
||||
|
|
|
@ -609,7 +609,8 @@ class TestUUIDField(FieldValues):
|
|||
284758210125106368185219588917561929842: uuid.UUID('d63a6fb6-88d5-40c7-a91c-9edf73283072')
|
||||
}
|
||||
invalid_inputs = {
|
||||
'825d7aeb-05a9-45b5-a5b7': ['"825d7aeb-05a9-45b5-a5b7" is not a valid UUID.']
|
||||
'825d7aeb-05a9-45b5-a5b7': ['"825d7aeb-05a9-45b5-a5b7" is not a valid UUID.'],
|
||||
(1, 2, 3): ['"(1, 2, 3)" is not a valid UUID.']
|
||||
}
|
||||
outputs = {
|
||||
uuid.UUID('825d7aeb-05a9-45b5-a5b7-05df87923cda'): '825d7aeb-05a9-45b5-a5b7-05df87923cda'
|
||||
|
|
Loading…
Reference in New Issue
Block a user