mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-13 05:06:53 +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:
|
try:
|
||||||
if isinstance(data, six.integer_types):
|
if isinstance(data, six.integer_types):
|
||||||
return uuid.UUID(int=data)
|
return uuid.UUID(int=data)
|
||||||
else:
|
elif isinstance(data, six.string_types):
|
||||||
return uuid.UUID(hex=data)
|
return uuid.UUID(hex=data)
|
||||||
except (ValueError, TypeError):
|
else:
|
||||||
|
self.fail('invalid', value=data)
|
||||||
|
except (ValueError):
|
||||||
self.fail('invalid', value=data)
|
self.fail('invalid', value=data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
|
@ -609,7 +609,8 @@ class TestUUIDField(FieldValues):
|
||||||
284758210125106368185219588917561929842: uuid.UUID('d63a6fb6-88d5-40c7-a91c-9edf73283072')
|
284758210125106368185219588917561929842: uuid.UUID('d63a6fb6-88d5-40c7-a91c-9edf73283072')
|
||||||
}
|
}
|
||||||
invalid_inputs = {
|
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 = {
|
outputs = {
|
||||||
uuid.UUID('825d7aeb-05a9-45b5-a5b7-05df87923cda'): '825d7aeb-05a9-45b5-a5b7-05df87923cda'
|
uuid.UUID('825d7aeb-05a9-45b5-a5b7-05df87923cda'): '825d7aeb-05a9-45b5-a5b7-05df87923cda'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user