urlmatch: Use None for match-all path
This commit is contained in:
parent
8fd0690959
commit
867f2a8e2b
@ -55,7 +55,7 @@ class UrlPattern:
|
||||
not file/ftp. We deviate from that as per-URL settings aren't
|
||||
security relevant.
|
||||
_host: The host to match to, or None for any host.
|
||||
_path: The path to match to, or None for any path. (FIXME true?)
|
||||
_path: The path to match to, or None for any path.
|
||||
_port: The port to match to as integer, or None for any port.
|
||||
"""
|
||||
|
||||
@ -124,7 +124,8 @@ class UrlPattern:
|
||||
def _init_path(self, parsed):
|
||||
if self._scheme == 'about' and not parsed.path.strip():
|
||||
raise ParseError("Pattern without path")
|
||||
self._path = parsed.path
|
||||
|
||||
self._path = None if parsed.path == '/*' else parsed.path
|
||||
|
||||
def _init_host(self, parsed):
|
||||
"""Parse the host from the given URL.
|
||||
@ -228,6 +229,9 @@ class UrlPattern:
|
||||
return self._port is None or self._port == port
|
||||
|
||||
def _matches_path(self, path):
|
||||
if self._path is None:
|
||||
return True
|
||||
|
||||
# Match 'google.com' with 'google.com/'
|
||||
# FIXME use the no-copy approach Chromium has in URLPattern::MatchesPath
|
||||
# for performance?
|
||||
|
@ -107,7 +107,7 @@ class TestMatchAllPagesForGivenScheme:
|
||||
assert up._host is None
|
||||
assert up._match_subdomains
|
||||
assert not up._match_all
|
||||
assert up._path == '/*'
|
||||
assert up._path is None
|
||||
|
||||
@pytest.mark.parametrize('url, expected', [
|
||||
("http://google.com", True),
|
||||
@ -202,7 +202,7 @@ class TestMatchIpAddresses:
|
||||
assert up._host == host
|
||||
assert up._match_subdomains == match_subdomains
|
||||
assert not up._match_all
|
||||
assert up._path == '/*'
|
||||
assert up._path is None
|
||||
|
||||
@pytest.mark.parametrize('pattern, expected', [
|
||||
("http://127.0.0.1/*", True),
|
||||
@ -225,7 +225,7 @@ class TestMatchChromeUrls:
|
||||
assert up._host == 'favicon'
|
||||
assert not up._match_subdomains
|
||||
assert not up._match_all
|
||||
assert up._path == '/*'
|
||||
assert up._path is None
|
||||
|
||||
@pytest.mark.parametrize('url, expected', [
|
||||
("chrome://favicon/http://google.com", True),
|
||||
|
Loading…
Reference in New Issue
Block a user