Skip to content

Commit

Permalink
Pass unquote thru add_route (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins committed Dec 21, 2022
1 parent e639db1 commit 79687f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit 79687f2

Please sign in to comment.