Skip to content

Commit

Permalink
If a trie is empty, find_all should return []
Browse files Browse the repository at this point in the history
If a trie is empty, there is no point in validating its IP type or running any of the rest of the logic. Indeed, if you validate an IP v6 against an empty trie, you will get an error (because self.v6 always defaults to false, and will not be changed until at least one IP v6 item is added to the trie).
  • Loading branch information
Huji committed Jul 31, 2019
1 parent 2e6fe49 commit 3bef334
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Store CIDR IP addresses (both v4 and v6) in a trie for easy lookup.
Read the documentation `here
<https://cidr-trie.readthedocs.io/en/latest/>`_.

Requirements
------------
cidr-trie requires Python 3.6 or above.

Installation
------------

Expand Down
2 changes: 2 additions & 0 deletions cidr_trie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ def find_all(self, prefix: str, children: bool=False) -> List[Tuple[str, Any]]:
Raises:
ValueError: When trying to find an IPv4 address in a v6 trie and vice-versa.
"""
if self.size == 0:
return []
self.validate_ip_type_for_trie(prefix)
result = []
ip, mask = cidr_atoi(prefix)
Expand Down

0 comments on commit 3bef334

Please sign in to comment.