From 6fc8fc17eb9d93b021d4d81649e1606f2038b7ee Mon Sep 17 00:00:00 2001 From: Huji Lee Date: Fri, 12 Jul 2019 21:34:26 -0400 Subject: [PATCH] If a trie is empty, find_all should return [] 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). --- cidr_trie/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cidr_trie/__init__.py b/cidr_trie/__init__.py index b31a012..f993532 100644 --- a/cidr_trie/__init__.py +++ b/cidr_trie/__init__.py @@ -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)