From 7fc53ae78ad8a41b5244924d6768b7249a694c78 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 6 Mar 2018 09:45:06 +0100 Subject: [PATCH] Make path optional in URL patterns See #3622 --- qutebrowser/utils/urlmatch.py | 5 +++-- tests/unit/utils/test_urlmatch.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/qutebrowser/utils/urlmatch.py b/qutebrowser/utils/urlmatch.py index 0e83c7420..fcddd0fe7 100644 --- a/qutebrowser/utils/urlmatch.py +++ b/qutebrowser/utils/urlmatch.py @@ -144,8 +144,9 @@ class UrlPattern: if parsed.path == '/*': self._path = None elif parsed.path == '': - # We want to make it possible to leave off a trailing slash. - self._path = '/' + # When the user doesn't add a trailing slash, we assume the pattern + # matches any path. + self._path = None else: self._path = parsed.path diff --git a/tests/unit/utils/test_urlmatch.py b/tests/unit/utils/test_urlmatch.py index cb4e41767..88da166ca 100644 --- a/tests/unit/utils/test_urlmatch.py +++ b/tests/unit/utils/test_urlmatch.py @@ -112,6 +112,16 @@ def test_port(pattern, port): assert up._port == port +@pytest.mark.parametrize('pattern, path', [ + ("http://foo/", '/'), + ("http://foo", None), + ("http://foo/*", None), +]) +def test_parse_path(pattern, path): + up = urlmatch.UrlPattern(pattern) + assert up._path == path + + class TestMatchAllPagesForGivenScheme: @pytest.fixture