~lioploum/offpunk

d4272877843eff9ea96c095960b46603ce0b11fe — Ploum 3 months ago 4a3ec61
offpunk: fix IPv6 as an URL (bug #40)
2 files changed, 13 insertions(+), 2 deletions(-)

M CHANGELOG
M offutils.py
M CHANGELOG => CHANGELOG +2 -0
@@ 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)

M offutils.py => offutils.py +11 -2
@@ 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: