Make path optional in URL patterns

See #3622
This commit is contained in:
Florian Bruhin 2018-03-06 09:45:06 +01:00
parent de3d2b1cb1
commit 7fc53ae78a
2 changed files with 13 additions and 2 deletions

View File

@ -144,8 +144,9 @@ class UrlPattern:
if parsed.path == '/*':
self._path = None
elif parsed.path == '':
# We want to make it possible to leave off a trailing slash.
self._path = '/'
# When the user doesn't add a trailing slash, we assume the pattern
# matches any path.
self._path = None
else:
self._path = parsed.path

View File

@ -112,6 +112,16 @@ def test_port(pattern, port):
assert up._port == port
@pytest.mark.parametrize('pattern, path', [
("http://foo/", '/'),
("http://foo", None),
("http://foo/*", None),
])
def test_parse_path(pattern, path):
up = urlmatch.UrlPattern(pattern)
assert up._path == path
class TestMatchAllPagesForGivenScheme:
@pytest.fixture