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