mirror of
https://github.com/simonw/datasette.git
synced 2026-11-13 21:58:31 +01:00
Tilde-decode custom page path variables, refs #1732
Wildcard custom pages (e.g. templates/pages/{topic}.html) passed the raw
tilde-encoded path segment straight into the template context, so a URL
like /topic_hello~20world rendered "hello~20world" instead of "hello
world" - and ids containing spaces or slashes never matched user data.
Tilde-decode the captured groups, matching how the database/table/row
url_vars are already decoded elsewhere in the router.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
481df7ff6d
commit
0a55fcbd6a
2 changed files with 27 additions and 1 deletions
|
|
@ -92,6 +92,24 @@ def test_custom_route_pattern(custom_pages_client, path, expected):
|
|||
assert response.text.strip() == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"path,expected",
|
||||
[
|
||||
# Tilde-encoded path variables should reach the template decoded
|
||||
# https://github.com/simonw/datasette/issues/1732
|
||||
("/topic_hello~20world", "Topic page for hello world"),
|
||||
("/topic_caf~C3~A9", "Topic page for café"),
|
||||
("/topic_a~2Fb/x~20y", "Slug: x y, Topic: a/b"),
|
||||
],
|
||||
)
|
||||
def test_custom_route_pattern_decodes_path_variables(
|
||||
custom_pages_client, path, expected
|
||||
):
|
||||
response = custom_pages_client.get(path)
|
||||
assert response.status == 200
|
||||
assert response.text.strip() == expected
|
||||
|
||||
|
||||
def test_custom_route_pattern_404(custom_pages_client):
|
||||
response = custom_pages_client.get("/route_OhNo")
|
||||
assert response.status == 404
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue