1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #24708 -- Handled non-string values in GenericIPAddressField.to_python()

This commit is contained in:
Pradeek
2015-04-27 21:52:48 +05:30
committed by Tim Graham
parent e7e39d32fd
commit 6123e6134f
2 changed files with 15 additions and 1 deletions

View File

@@ -1963,7 +1963,12 @@ class GenericIPAddressField(Field):
return "GenericIPAddressField"
def to_python(self, value):
if value and ':' in value:
if value is None:
return None
if not isinstance(value, six.string_types):
value = force_text(value)
value = value.strip()
if ':' in value:
return clean_ipv6_address(value,
self.unpack_ipv4, self.error_messages['invalid'])
return value