From 18848315f5b810002dcdccbec6a1e43eb15531ef Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 20 Feb 2018 22:45:16 +0100 Subject: [PATCH] urlmatch: Make it possible to leave off trailing slash --- qutebrowser/utils/urlmatch.py | 8 +++++++- tests/unit/utils/test_urlmatch.py | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/qutebrowser/utils/urlmatch.py b/qutebrowser/utils/urlmatch.py index 6bded760b..0e83c7420 100644 --- a/qutebrowser/utils/urlmatch.py +++ b/qutebrowser/utils/urlmatch.py @@ -141,7 +141,13 @@ class UrlPattern: if self._scheme == 'about' and not parsed.path.strip(): raise ParseError("Pattern without path") - self._path = None if parsed.path == '/*' else parsed.path + if parsed.path == '/*': + self._path = None + elif parsed.path == '': + # We want to make it possible to leave off a trailing slash. + self._path = '/' + else: + self._path = parsed.path def _init_host(self, parsed): """Parse the host from the given URL. diff --git a/tests/unit/utils/test_urlmatch.py b/tests/unit/utils/test_urlmatch.py index a89913456..9622d7794 100644 --- a/tests/unit/utils/test_urlmatch.py +++ b/tests/unit/utils/test_urlmatch.py @@ -389,6 +389,13 @@ def test_ignore_missing_slashes(): assert not pattern1.matches(url2) +def test_trailing_slash(): + """Contrary to Chromium, we allow to leave off a trailing slash.""" + url = QUrl('http://www.example.com/') + pattern = urlmatch.UrlPattern('http://www.example.com') + assert pattern.matches(url) + + @pytest.mark.parametrize('pattern', ['*://example.com/*', '*://example.com./*']) @pytest.mark.parametrize('url', ['http://example.com/',