Added validation to UUIDField to properly catch invalid input types (lists, tuples, etc).

This commit is contained in:
bphillips 2015-12-01 14:09:10 -05:00
parent d2f90fd6af
commit c153bcb479
2 changed files with 6 additions and 3 deletions

View File

@ -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

View File

@ -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'