match minimizes ipv6 urls

This commit is contained in:
Jesko 2018-08-08 16:55:43 +02:00
parent 599ac5ca23
commit 4ce5d99b24
2 changed files with 11 additions and 0 deletions

View File

@ -30,6 +30,7 @@ import fnmatch
import urllib.parse
from qutebrowser.utils import utils, qtutils
from PyQt5.QtCore import QUrl
class ParseError(Exception):
@ -177,6 +178,13 @@ class UrlPattern:
assert self._host is None
return
if not utils.raises(ValueError, ipaddress.IPv6Address, parsed.netloc[1:-1]):
# Using QUrl parsing to minimize ipv6 addresses
url = QUrl()
url.setHost(parsed.hostname)
self._host = url.host()
return
# FIXME what about multiple dots?
host_parts = parsed.hostname.rstrip('.').split('.')
if host_parts[0] == '*':

View File

@ -257,6 +257,9 @@ class TestMatchIpAddresses:
("http://127.0.0.1/*", "127.0.0.1", False),
("http://*.0.0.1/*", "0.0.1", True),
("http://[::1]/*", "::1", False),
("http://[0::1]/*", "::1", False),
("http://[::01]/*", "::1", False),
("http://[0:0:0:0:20::1]/*", "::20:0:0:1", False),
])
def test_attrs(self, pattern, host, match_subdomains):
up = urlmatch.UrlPattern(pattern)