match minimizes ipv6 urls
This commit is contained in:
parent
599ac5ca23
commit
4ce5d99b24
@ -30,6 +30,7 @@ import fnmatch
|
|||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
from qutebrowser.utils import utils, qtutils
|
from qutebrowser.utils import utils, qtutils
|
||||||
|
from PyQt5.QtCore import QUrl
|
||||||
|
|
||||||
|
|
||||||
class ParseError(Exception):
|
class ParseError(Exception):
|
||||||
@ -177,6 +178,13 @@ class UrlPattern:
|
|||||||
assert self._host is None
|
assert self._host is None
|
||||||
return
|
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?
|
# FIXME what about multiple dots?
|
||||||
host_parts = parsed.hostname.rstrip('.').split('.')
|
host_parts = parsed.hostname.rstrip('.').split('.')
|
||||||
if host_parts[0] == '*':
|
if host_parts[0] == '*':
|
||||||
|
@ -257,6 +257,9 @@ class TestMatchIpAddresses:
|
|||||||
("http://127.0.0.1/*", "127.0.0.1", False),
|
("http://127.0.0.1/*", "127.0.0.1", False),
|
||||||
("http://*.0.0.1/*", "0.0.1", True),
|
("http://*.0.0.1/*", "0.0.1", True),
|
||||||
("http://[::1]/*", "::1", False),
|
("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):
|
def test_attrs(self, pattern, host, match_subdomains):
|
||||||
up = urlmatch.UrlPattern(pattern)
|
up = urlmatch.UrlPattern(pattern)
|
||||||
|
Loading…
Reference in New Issue
Block a user