diff --git a/CHANGELOG b/CHANGELOG index 0d4b8f2..cd88318 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ # Offpunk History +## 2.3 - Unreleased +- offpunk: fix IPv6 as an URL (bug #40) ## 2.2 - February 13th 2023 - cache folder is now configurable through $OFFPUNK_CACHE_PATH environment variable (by prx) diff --git a/offutils.py b/offutils.py index 0d4244c..a266a18 100644 --- a/offutils.py +++ b/offutils.py @@ -99,7 +99,7 @@ def fix_ipv6_url(url): netloc, rest = schemaless.split("/",1) if netloc.count(":") > 2 and "[" not in netloc and "]" not in netloc: schemaless = "[" + netloc + "]" + "/" + rest - elif schemaless.count(":") > 2: + elif schemaless.count(":") > 2 and "[" not in schemaless and "]" not in schemaless: schemaless = "[" + schemaless + "]/" if schema: return schema + "://" + schemaless @@ -121,7 +121,16 @@ def looks_like_url(word): if mailto: return "@" in word elif not local: - return start and ("." in word or "localhost" in word) + if start: + #IPv4 + if "." in word or "localhost" in word: + return True + #IPv6 + elif "[" in word and ":" in word and "]" in word: + return True + else: return False + else: return False + return start and ("." in word or "localhost" in word or ":" in word) else: return "/" in word except ValueError: