urlmatch: Make it possible to leave off trailing slash
This commit is contained in:
parent
17b235b523
commit
18848315f5
@ -141,7 +141,13 @@ class UrlPattern:
|
||||
if self._scheme == 'about' and not parsed.path.strip():
|
||||
raise ParseError("Pattern without path")
|
||||
|
||||
self._path = None if parsed.path == '/*' else parsed.path
|
||||
if parsed.path == '/*':
|
||||
self._path = None
|
||||
elif parsed.path == '':
|
||||
# We want to make it possible to leave off a trailing slash.
|
||||
self._path = '/'
|
||||
else:
|
||||
self._path = parsed.path
|
||||
|
||||
def _init_host(self, parsed):
|
||||
"""Parse the host from the given URL.
|
||||
|
@ -389,6 +389,13 @@ def test_ignore_missing_slashes():
|
||||
assert not pattern1.matches(url2)
|
||||
|
||||
|
||||
def test_trailing_slash():
|
||||
"""Contrary to Chromium, we allow to leave off a trailing slash."""
|
||||
url = QUrl('http://www.example.com/')
|
||||
pattern = urlmatch.UrlPattern('http://www.example.com')
|
||||
assert pattern.matches(url)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('pattern', ['*://example.com/*',
|
||||
'*://example.com./*'])
|
||||
@pytest.mark.parametrize('url', ['http://example.com/',
|
||||
|
Loading…
Reference in New Issue
Block a user