Skip to content

Commit 9a045bb

Browse files
johndlongkvesteri
authored andcommitted
Fix IPv4 formatted IP address returning True on ipv6 (python-validators#85)
1 parent 8cf1e8f commit 9a045bb

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

tests/test_ipv4.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import pytest
33

4-
from validators import ipv4, ValidationFailure
4+
from validators import ipv4, ipv6, ValidationFailure
55

66

77
@pytest.mark.parametrize(('address',), [
@@ -11,6 +11,7 @@
1111
])
1212
def test_returns_true_on_valid_ipv4_address(address):
1313
assert ipv4(address)
14+
assert not ipv6(address)
1415

1516

1617
@pytest.mark.parametrize(('address',), [

tests/test_ipv6.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import pytest
33

4-
from validators import ipv6, ValidationFailure
4+
from validators import ipv4, ipv6, ValidationFailure
55

66

77
@pytest.mark.parametrize(('address',), [
@@ -13,6 +13,7 @@
1313
])
1414
def test_returns_true_on_valid_ipv6_address(address):
1515
assert ipv6(address)
16+
assert not ipv4(address)
1617

1718

1819
@pytest.mark.parametrize(('address',), [

validators/ip_address.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def ipv6(value):
5959
:param value: IP address string to validate
6060
"""
6161
ipv6_groups = value.split(':')
62+
if len(ipv6_groups) == 1:
63+
return False
6264
ipv4_groups = ipv6_groups[-1].split('.')
6365

6466
if len(ipv4_groups) > 1:

0 commit comments

Comments
 (0)