Changed:
- same_domain: If the tld is unknown, only return True if the hostnames are the same - Fix when starting without an open page
This commit is contained in:
parent
f806eefba6
commit
a346644c71
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user