This commit is contained in:
TowyTowy 2026-10-17 07:54:32 -07:00 • committed by GitHub
commit 73bb2d6aa5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View file

@ -3387,7 +3387,15 @@ class DatasetteRouter:
for regex, wildcard_template in page_routes:
match = regex.match(route_path)
if match is not None:
context.update(match.groupdict())
# Tilde-decode captured path variables so templates see
# the real value - e.g. "hello world" not "hello~20world"
# https://github.com/simonw/datasette/issues/1732
context.update(
{
key: tilde_decode(value)
for key, value in match.groupdict().items()
}
)
template = wildcard_template
break

View file

@ -94,6 +94,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