Fix handling of nested custom page wildcard paths, closes #996

pull/1000/head
Simon Willison 2020-10-07 15:51:11 -07:00
rodzic b37431976c
commit 5070425817
4 zmienionych plików z 11 dodań i 4 usunięć

Wyświetl plik

@ -1204,7 +1204,7 @@ def route_pattern_from_filepath(filepath):
re_bits.append("(?P<{}>[^/]*)".format(bit[1:-1]))
else:
re_bits.append(re.escape(bit))
return re.compile("".join(re_bits))
return re.compile("^" + "".join(re_bits) + "$")
class NotFoundExplicit(NotFound):

Wyświetl plik

@ -64,10 +64,15 @@ def test_redirect2(custom_pages_client):
assert "/example" == response.headers["Location"]
def test_custom_route_pattern(custom_pages_client):
response = custom_pages_client.get("/route_Sally")
@pytest.mark.parametrize("path,expected", [
("/route_Sally", "<p>Hello from Sally</p>"),
("/topic_python", "Topic page for python"),
("/topic_python/info", "Slug: info, Topic: python"),
])
def test_custom_route_pattern(custom_pages_client, path, expected):
response = custom_pages_client.get(path)
assert response.status == 200
assert response.text.strip() == "<p>Hello from Sally</p>"
assert response.text.strip() == expected
def test_custom_route_pattern_404(custom_pages_client):

Wyświetl plik

@ -0,0 +1 @@
Topic page for {{ topic }}

Wyświetl plik

@ -0,0 +1 @@
Slug: {{ slug }}, Topic: {{ topic }}