diff options
author | Florian Bruhin <me@the-compiler.org> | 2019-12-23 15:43:23 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2019-12-23 15:43:23 +0100 |
commit | 86fca3e99ee4836f5f591831eb93a09ffb8231d2 (patch) | |
tree | 3d27993d9c4a964005b7ea4e461b258dd7a7e574 | |
parent | 1be156d289182ad91d1bdca08549027ea3653fad (diff) | |
parent | aaf5d10cf1ec4816a4a60dc5f8e031a0fd82c2c7 (diff) | |
download | qutebrowser-86fca3e99ee4836f5f591831eb93a09ffb8231d2.tar.gz qutebrowser-86fca3e99ee4836f5f591831eb93a09ffb8231d2.zip |
Merge remote-tracking branch 'origin/pr/5139'
-rw-r--r-- | qutebrowser/utils/urlutils.py | 15 | ||||
-rw-r--r-- | tests/unit/utils/test_urlutils.py | 2 |
2 files changed, 8 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)) diff --git a/tests/unit/utils/test_urlutils.py b/tests/unit/utils/test_urlutils.py index b6d73319d..49cee6382 100644 --- a/tests/unit/utils/test_urlutils.py +++ b/tests/unit/utils/test_urlutils.py @@ -346,7 +346,9 @@ def test_get_search_url_invalid(url): (True, True, False, '127.0.0.1'), (True, True, False, '::1'), (True, True, True, '2001:41d0:2:6c11::1'), + (True, True, True, '[2001:41d0:2:6c11::1]:8000'), (True, True, True, '94.23.233.17'), + (True, True, True, '94.23.233.17:8000'), # Special URLs (True, True, False, 'file:///tmp/foo'), (True, True, False, 'about:blank'), |