mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 16:24:18 +03:00
Merge pull request #3687 from benred42/3679-UUIDField-validation
Fixed #3679 -- UUID Validation
This commit is contained in:
commit
9f74b8860e
|
@ -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