Handle invalid QUrl objects in HostBlocker.is_blocked

For some requests, we don't know a first party URL, so we get an invalid QUrl
object from QtWebKit/QtWebEngine.

However, the config system wants either a valid QUrl or None (for the global
value), so we don't accidentally pass an invalid QUrl in. Thus, do the
conversion here.
This commit is contained in:
Florian Bruhin 2018-10-05 23:37:45 +02:00
parent 14957c75ff
commit c6dc9206e6

View File

@ -112,9 +112,12 @@ class HostBlocker:
def is_blocked(self, url, first_party_url=None):
"""Check if the given URL (as QUrl) is blocked."""
if first_party_url is not None and not first_party_url.isValid():
first_party_url = None
if not config.instance.get('content.host_blocking.enabled',
url=first_party_url):
return False
host = url.host()
return ((host in self._blocked_hosts or
host in self._config_blocked_hosts) and