diff options
Diffstat (limited to 'qutebrowser/utils/urlutils.py')
-rw-r--r-- | qutebrowser/utils/urlutils.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index 2908327dd..7e7d42e90 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -138,18 +138,15 @@ def _is_url_naive(urlstr: str) -> bool: """ url = qurl_from_user_input(urlstr) assert url.isValid() + host = url.host() - if not utils.raises(ValueError, ipaddress.ip_address, urlstr): - # Valid IPv4/IPv6 address + # Valid IPv4/IPv6 address. Qt converts things like "23.42" or "1337" or + # "0xDEAD" to IP addresses, which we don't like, so we check if the host + # from Qt is part of the input. + if (not utils.raises(ValueError, ipaddress.ip_address, host) and + host in urlstr): return True - # Qt treats things like "23.42" or "1337" or "0xDEAD" as valid URLs - # which we don't want to. Note we already filtered *real* valid IPs - # above. - if not QHostAddress(urlstr).isNull(): - return False - - host = url.host() tld = r'\.([^.0-9_-]+|xn--[a-z0-9-]+)$' forbidden = r'[\u0000-\u002c\u002f\u003a-\u0060\u007b-\u00b6]' return bool(re.search(tld, host) and not re.search(forbidden, host)) |