Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass unquote thru add_route #2639

Merged
merged 2 commits into from Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions sanic/mixins/routes.py
Expand Up @@ -218,6 +218,7 @@ def add_route(
stream: bool = False,
version_prefix: str = "/v",
error_format: Optional[str] = None,
unquote: bool = False,
**ctx_kwargs: Any,
) -> RouteHandler:
"""A helper method to register class instance or
Expand Down Expand Up @@ -264,6 +265,7 @@ def add_route(
name=name,
version_prefix=version_prefix,
error_format=error_format,
unquote=unquote,
**ctx_kwargs,
)(handler)
return handler
Expand Down
15 changes: 15 additions & 0 deletions tests/test_routes.py
Expand Up @@ -803,6 +803,21 @@ async def handler2(request):
assert response.text == "OK2"


@pytest.mark.parametrize("unquote", [True, False, None])
def test_unquote_add_route(app, unquote):
async def handler1(_, foo):
return text(foo)

app.add_route(handler1, "/<foo>", unquote=unquote)
value = "啊" if unquote else r"%E5%95%8A"

_, response = app.test_client.get("/啊")
assert response.text == value

_, response = app.test_client.get(r"/%E5%95%8A")
assert response.text == value


def test_dynamic_add_route(app):

results = []
Expand Down