From d266190518d35221fb44a39b72d41761880db672 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 14 Feb 2018 23:32:40 +0100 Subject: [PATCH] urlmatch: Improve port tests --- qutebrowser/utils/urlmatch.py | 2 +- tests/unit/utils/test_urlmatch.py | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/qutebrowser/utils/urlmatch.py b/qutebrowser/utils/urlmatch.py index 07355e885..f171d77be 100644 --- a/qutebrowser/utils/urlmatch.py +++ b/qutebrowser/utils/urlmatch.py @@ -139,7 +139,7 @@ class UrlPattern: 'file': False, 'chrome': False, 'qute': False, 'about': False} if not allows_ports[self._scheme] and self._port is not None: - raise ParseError("Ports unsupported with {} scheme".format( + raise ParseError("Ports are unsupported with {} scheme".format( self._scheme)) def __repr__(self): diff --git a/tests/unit/utils/test_urlmatch.py b/tests/unit/utils/test_urlmatch.py index eb630f99b..47fc8b82b 100644 --- a/tests/unit/utils/test_urlmatch.py +++ b/tests/unit/utils/test_urlmatch.py @@ -53,6 +53,14 @@ from qutebrowser.utils import urlmatch ("http://foo.*.bar/baz", "Invalid host wildcard"), ("http://fo.*.ba:123/baz", "Invalid host wildcard"), ("http://foo.*/bar", "Invalid host wildcard"), + + # Chromium: PARSE_ERROR_INVALID_PORT + ("http://foo:/", "Empty port"), + ("http://*.foo:/", "Empty port"), + ("http://foo:com/", "Invalid port"), + ("http://foo:123456/", "Invalid port"), + ("http://foo:80:80/monkey", "Invalid port"), + ("chrome://foo:1234/bar", "Ports are unsupported with chrome scheme"), ]) def test_invalid_patterns(pattern, error): with pytest.raises(urlmatch.ParseError, match=error): @@ -70,19 +78,6 @@ def test_invalid_patterns(pattern, error): # FIXME Why is this valid in Chromium? # ("file://foo:1234/bar", "*"), ]) -def test_port_valid(pattern, port): +def test_port(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(urlmatch.ParseError): - urlmatch.UrlPattern(pattern)