Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove unnecessary check
  • Loading branch information
Ins1ne committed Mar 4, 2015
commit c44376c613333cce36e830eb846b4cdcecabaf6c
6 changes: 1 addition & 5 deletions rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,17 +669,13 @@ def __init__(self, protocol='both', unpack_ipv4=False, **kwargs):
self.validators.extend(validators)

def to_internal_value(self, data):
if data == '' and self.allow_blank:
return ''
data = data.strip()

if data and ':' in data:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be wrong, but this line looks like we assume the user will always use 'both' protocol, but what happen if we can't unpack the ipv4 address to an ipv6 one? In this case ':' won't be present inside the ip string and the whole check will fail or be skipped.

Is this situation already handled by the use of ip_address_validators method? Should we add a particular test case that handle the situation where the user pass (protocol='ipv4', unpack_ipv4=True) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds right!

try:
return clean_ipv6_address(data, self.unpack_ipv4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be changed to:

data = clean_ipv6_address(data, self.unpack_ipv4)

or we just "clean" the ipv6 address without validating it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a wrong assumption. is_valid_ipv6_address is called from clean_ipv6_address https://github.com/django/django/blob/0ed7d155635da9f79d4dd67e4889087d3673c6da/django/utils/ipv6.py#L35

except DjangoValidationError:
self.fail('invalid', value=data)

return data
return super(IPAddressField, self).to_internal_value(data)


# Number types...
Expand Down