diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-11-23 20:04:15 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-11-23 20:18:12 +0100 |
commit | 699a5a59f5c164d1cbe5093a9cd0f5b9afbcfe62 (patch) | |
tree | 8bec9bb7ca7e6282df649167697f94421b733ff9 | |
parent | 120f8ce1d48cee39b785b9e74cb541652a2ca26d (diff) | |
download | qutebrowser-699a5a59f5c164d1cbe5093a9cd0f5b9afbcfe62.tar.gz qutebrowser-699a5a59f5c164d1cbe5093a9cd0f5b9afbcfe62.zip |
urlutils: Consider scheme/port for same_domain()
See #5892
-rw-r--r-- | qutebrowser/utils/urlutils.py | 7 | ||||
-rw-r--r-- | tests/unit/utils/test_urlutils.py | 5 |
2 files changed, 11 insertions, 1 deletions
diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index 977bd7cc6..41d20e734 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -467,12 +467,19 @@ def same_domain(url1: QUrl, url2: QUrl) -> bool: For example example.com and www.example.com are considered the same. but example.co.uk and test.co.uk are not. + If the URL's schemes or ports are different, they are always treated as not equal. + Return: True if the domains are the same, False otherwise. """ ensure_valid(url1) ensure_valid(url2) + if url1.scheme() != url2.scheme(): + return False + if url1.port() != url2.port(): + return False + suffix1 = url1.topLevelDomain() suffix2 = url2.topLevelDomain() if not suffix1: diff --git a/tests/unit/utils/test_urlutils.py b/tests/unit/utils/test_urlutils.py index eac2b6c1d..0167f6cee 100644 --- a/tests/unit/utils/test_urlutils.py +++ b/tests/unit/utils/test_urlutils.py @@ -615,7 +615,7 @@ class TestInvalidUrlError: @pytest.mark.parametrize('are_same, url1, url2', [ (True, 'http://example.com', 'http://www.example.com'), - (True, 'http://bbc.co.uk', 'https://www.bbc.co.uk'), + (True, 'http://bbc.co.uk', 'http://www.bbc.co.uk'), (True, 'http://many.levels.of.domains.example.com', 'http://www.example.com'), (True, 'http://idn.иком.museum', 'http://idn2.иком.museum'), (True, 'http://one.not_a_valid_tld', 'http://one.not_a_valid_tld'), @@ -624,6 +624,9 @@ class TestInvalidUrlError: (False, 'https://example.kids.museum', 'http://example.kunst.museum'), (False, 'http://idn.иком.museum', 'http://idn.ירושלים.museum'), (False, 'http://one.not_a_valid_tld', 'http://two.not_a_valid_tld'), + + (False, 'http://example.org', 'https://example.org'), # different scheme + (False, 'http://example.org:80', 'http://example.org:8080'), # different port ]) def test_same_domain(are_same, url1, url2): """Test same_domain.""" |