From 770a95c1013d5b4a274e350b0487870dc979b675 Mon Sep 17 00:00:00 2001 From: Ellis Date: Sun, 16 Sep 2018 19:12:49 -0400 Subject: [PATCH] Changed is_whitelisted_host to use URL Patterns fixes #4179 --- qutebrowser/browser/adblock.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/qutebrowser/browser/adblock.py b/qutebrowser/browser/adblock.py index affd80eaf..e265b74f0 100644 --- a/qutebrowser/browser/adblock.py +++ b/qutebrowser/browser/adblock.py @@ -30,6 +30,7 @@ from qutebrowser.browser import downloads from qutebrowser.config import config from qutebrowser.utils import objreg, standarddir, log, message from qutebrowser.commands import cmdutils +from qutebrowser.utils import urlmatch def guess_zip_filename(zf): @@ -61,14 +62,14 @@ def get_fileobj(byte_io): return byte_io -def is_whitelisted_host(host): - """Check if the given host is on the adblock whitelist. +def is_whitelisted_host(url): + """Check if the given url is on the adblock whitelist. Args: - host: The host of the request as string. + url: The url to check. """ for pattern in config.val.content.host_blocking.whitelist: - if fnmatch.fnmatch(host, pattern.lower()): + if urlmatch.URLPattern(pattern).matches(url): return True return False @@ -118,7 +119,7 @@ class HostBlocker: host = url.host() return ((host in self._blocked_hosts or host in self._config_blocked_hosts) and - not is_whitelisted_host(host)) + not is_whitelisted_host(url.toString())) def _read_hosts_file(self, filename, target): """Read hosts from the given filename.