From a346644c716303f1b551056ba14d77b21e5ba62d Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Sat, 27 Jun 2015 21:14:19 +0200 Subject: [PATCH] Changed: - same_domain: If the tld is unknown, only return True if the hostnames are the same - Fix when starting without an open page --- qutebrowser/browser/network/networkmanager.py | 13 ++++++++----- qutebrowser/utils/urlutils.py | 3 +++ tests/utils/test_urlutils.py | 5 ++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/qutebrowser/browser/network/networkmanager.py b/qutebrowser/browser/network/networkmanager.py index 7ebb80a2e..7005336fd 100644 --- a/qutebrowser/browser/network/networkmanager.py +++ b/qutebrowser/browser/network/networkmanager.py @@ -21,9 +21,10 @@ import collections -from PyQt5.QtCore import (pyqtSlot, pyqtSignal, PYQT_VERSION, QCoreApplication) +from PyQt5.QtCore import (pyqtSlot, pyqtSignal, PYQT_VERSION, QCoreApplication, + QUrl, QByteArray) from PyQt5.QtNetwork import (QNetworkAccessManager, QNetworkReply, QSslError, - QSslSocket, QUrl, QByteArray) + QSslSocket) from qutebrowser.config import config from qutebrowser.utils import (message, log, usertypes, utils, objreg, qtutils, @@ -339,12 +340,14 @@ class NetworkManager(QNetworkAccessManager): current_url = objreg.get('tabbed-browser', scope='window', window=self._win_id).currentWidget().url() - if (config.get('network', 'referer-header') == 'never' or - (config.get('network', 'referer-header') == 'same-domain' and - urlutils.same_domain(req.url(), current_url))): + if config.get('network', 'referer-header') == 'never': # Note: using ''.encode('ascii') sends a header with no value, # instead of no header at all req.setRawHeader('Referer'.encode('ascii'), QByteArray()) + elif (config.get('network', 'referer-header') == 'same-domain' and + current_url.isValid() and + not urlutils.same_domain(req.url(), current_url)): + req.setRawHeader('Referer'.encode('ascii'), QByteArray()) accept_language = config.get('network', 'accept-language') if accept_language is not None: diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index 168e7aabf..a401ac4d5 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -411,6 +411,9 @@ def same_domain(url1, url2): suffix1 = url1.topLevelDomain() suffix2 = url2.topLevelDomain() + if suffix1 == '': + return url1.host() == url2.host() + if not suffix1 == suffix2: return False diff --git a/tests/utils/test_urlutils.py b/tests/utils/test_urlutils.py index 4f027ceff..969c5767c 100644 --- a/tests/utils/test_urlutils.py +++ b/tests/utils/test_urlutils.py @@ -239,6 +239,8 @@ class TestSameDomain: ('http://example.com', 'http://www.example.com'), ('http://bbc.co.uk', 'https://www.bbc.co.uk'), ('http://many.levels.of.domains.example.com', 'http://www.example.com'), + ('http://idn.иком.museum', 'http://idn2.иком.museum'), + ('http://one.not_a_valid_tld', 'http://one.not_a_valid_tld'), ) for host1, host2 in hosts: @@ -250,7 +252,8 @@ class TestSameDomain: hosts = ( ('http://bbc.co.uk', 'http://example.co.uk'), ('https://example.kids.museum', 'http://example.kunst.museum'), - ('http://idn.иком.museum', 'http://idn.ירושלים.museum') + ('http://idn.иком.museum', 'http://idn.ירושלים.museum'), + ('http://one.not_a_valid_tld', 'http://two.not_a_valid_tld'), ) for host1, host2 in hosts: