From 3c17bb97c0cea3628620579d6e0818e2fac880ab Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 14 Feb 2018 22:30:35 +0100 Subject: [PATCH] urlmatch: Start with port parsing --- qutebrowser/utils/urlmatch.py | 4 ++-- tests/unit/utils/test_urlmatch.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/qutebrowser/utils/urlmatch.py b/qutebrowser/utils/urlmatch.py index 211ac0475..665536959 100644 --- a/qutebrowser/utils/urlmatch.py +++ b/qutebrowser/utils/urlmatch.py @@ -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 diff --git a/tests/unit/utils/test_urlmatch.py b/tests/unit/utils/test_urlmatch.py index 26b4b6a59..03b7f947b 100644 --- a/tests/unit/utils/test_urlmatch.py +++ b/tests/unit/utils/test_urlmatch.py @@ -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)