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 #163

Merged
merged 1 commit 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_ext/extensions/http/methods.py
Expand Up @@ -92,6 +92,7 @@ def _add_handlers(app, _):
strict_slashes=group.strict,
name=name,
host=host,
unquote=group.unquote,
)
app.finalize()

Expand Down Expand Up @@ -138,5 +139,6 @@ def _add_handlers(app, _):
strict_slashes=group.strict,
name=name,
host=host,
unquote=group.unquote,
)
app.finalize()
18 changes: 18 additions & 0 deletions tests/extensions/http/test_methods.py
@@ -1,3 +1,4 @@
import pytest
from sanic import Sanic
from sanic.response import empty, text

Expand Down Expand Up @@ -85,3 +86,20 @@ async def foo_handler_two(_):

schema = get_docs()
assert "get" in schema["paths"]["/foo"]


# This test also appears in Core Sanic tests but is added here as well
# because of: https://github.com/sanic-org/sanic-ext/issues/148
@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