match minimizes ipv6 urls
This commit is contained in:
parent
599ac5ca23
commit
4ce5d99b24
@ -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] == '*':
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user