From 2d43a1d2e7b62429fc4bd4bf45aabd51f9115592 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 15 Feb 2018 16:42:41 +0100 Subject: [PATCH] urlmatch: Use None as default for host --- qutebrowser/utils/urlmatch.py | 9 ++++++++- tests/unit/utils/test_urlmatch.py | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/qutebrowser/utils/urlmatch.py b/qutebrowser/utils/urlmatch.py index bd5f17fa5..76a72c32e 100644 --- a/qutebrowser/utils/urlmatch.py +++ b/qutebrowser/utils/urlmatch.py @@ -53,7 +53,7 @@ class UrlPattern: Note that with Chromium, '*'/None only matches http/https and not file/ftp. We deviate from that as per-URL settings aren't security relevant. - _host: The host to match to, or None for any host. (FIXME true?) + _host: The host to match to, or None for any host. _path: The path to match to, or None for any path. (FIXME true?) _port: The port to match to as integer, or None for any port. """ @@ -139,6 +139,10 @@ class UrlPattern: host_parts = host_parts[1:] self._match_subdomains = True + if not host_parts: + self._host = None + return + self._host = '.'.join(host_parts) if self._host.endswith('.*'): @@ -184,6 +188,9 @@ class UrlPattern: # FIXME what about multiple dots? host = host.rstrip('.') + if self._host is None: + return True + # If the hosts are exactly equal, we have a match. if host == self._host: return True diff --git a/tests/unit/utils/test_urlmatch.py b/tests/unit/utils/test_urlmatch.py index accbb691f..cc5f4006a 100644 --- a/tests/unit/utils/test_urlmatch.py +++ b/tests/unit/utils/test_urlmatch.py @@ -103,7 +103,7 @@ class TestMatchAllPagesForGivenScheme: def test_attrs(self, up): assert up._scheme == 'http' - assert up._host == '' # FIXME '' or None? + assert up._host is None assert up._match_subdomains assert not up._match_all assert up._path == '/*' @@ -127,7 +127,7 @@ class TestMatchAllDomains: def test_attrs(self, up): assert up._scheme == 'https' - assert up._host == '' # FIXME '' or None? + assert up._host is None assert up._match_subdomains assert not up._match_all assert up._path == '/foo*' @@ -175,7 +175,7 @@ class TestMatchGlobEscaping: def test_attrs(self, up): assert up._scheme == 'file' - assert up._host == '' # FIXME '' or None? + assert up._host is None assert not up._match_subdomains assert not up._match_all assert up._path == r'/foo-bar\*baz'