urlmatch: Start with port parsing
This commit is contained in:
parent
1b8dfb6c36
commit
3c17bb97c0
@ -90,9 +90,9 @@ class UrlPattern:
|
||||
self._path = parsed.path
|
||||
|
||||
def _init_host(self, parsed):
|
||||
if self._scheme != 'about' and not parsed.netloc.strip():
|
||||
if self._scheme != 'about' and not parsed.hostname.strip():
|
||||
raise ValueError("Pattern without host")
|
||||
host_parts = parsed.netloc.split('.')
|
||||
host_parts = parsed.hostname.split('.')
|
||||
if host_parts[0] == '*':
|
||||
host_parts = host_parts[1:]
|
||||
self._match_subdomains = True
|
||||
|
@ -57,3 +57,30 @@ from qutebrowser.utils import urlmatch
|
||||
def test_invalid_patterns(pattern, error):
|
||||
with pytest.raises(ValueError, match=error):
|
||||
urlmatch.UrlPattern(pattern)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('pattern, port', [
|
||||
("http://foo:1234/", 1234),
|
||||
("http://foo:1234/bar", 1234),
|
||||
("http://*.foo:1234/", 1234),
|
||||
("http://*.foo:1234/bar", 1234),
|
||||
("http://:1234/", 1234),
|
||||
("http://foo:*/", "*"),
|
||||
("file://foo:1234/bar", "*"),
|
||||
])
|
||||
def test_port_valid(pattern, port):
|
||||
up = urlmatch.UrlPattern(pattern)
|
||||
assert up._port == port
|
||||
|
||||
|
||||
@pytest.mark.parametrize('pattern', [
|
||||
"http://foo:/",
|
||||
"http://*.foo:/",
|
||||
"http://foo:com/",
|
||||
"http://foo:123456/",
|
||||
"http://foo:80:80/monkey",
|
||||
"chrome://foo:1234/bar",
|
||||
])
|
||||
def test_port_invalid(pattern):
|
||||
with pytest.raises(ValueError, match='Invalid Port'):
|
||||
urlmatch.UrlPattern(pattern)
|
||||
|
Loading…
Reference in New Issue
Block a user