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:46:02 +0100 |
commit | 61b1ff2706bc1d75a227322600cec46f75b7b08b (patch) | |
tree | 2b0fd88db336c09cce63b4f987f3bd40f4b45d7a | |
parent | 259edeb576051f91b25acf0ed99e6f6e620ca6ff (diff) | |
download | qutebrowser-61b1ff2706bc1d75a227322600cec46f75b7b08b.tar.gz qutebrowser-61b1ff2706bc1d75a227322600cec46f75b7b08b.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 a14be78a8..c634fe74d 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -504,12 +504,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 df9d8b510..08ef892af 100644 --- a/tests/unit/utils/test_urlutils.py +++ b/tests/unit/utils/test_urlutils.py @@ -643,7 +643,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'), @@ -652,6 +652,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.""" |