Pass unquote thru add_route (#2639)
This commit is contained in:
parent
2abe66b670
commit
029f564032
|
@ -218,6 +218,7 @@ class RouteMixin(metaclass=SanicMeta):
|
||||||
stream: bool = False,
|
stream: bool = False,
|
||||||
version_prefix: str = "/v",
|
version_prefix: str = "/v",
|
||||||
error_format: Optional[str] = None,
|
error_format: Optional[str] = None,
|
||||||
|
unquote: bool = False,
|
||||||
**ctx_kwargs: Any,
|
**ctx_kwargs: Any,
|
||||||
) -> RouteHandler:
|
) -> RouteHandler:
|
||||||
"""A helper method to register class instance or
|
"""A helper method to register class instance or
|
||||||
|
@ -264,6 +265,7 @@ class RouteMixin(metaclass=SanicMeta):
|
||||||
name=name,
|
name=name,
|
||||||
version_prefix=version_prefix,
|
version_prefix=version_prefix,
|
||||||
error_format=error_format,
|
error_format=error_format,
|
||||||
|
unquote=unquote,
|
||||||
**ctx_kwargs,
|
**ctx_kwargs,
|
||||||
)(handler)
|
)(handler)
|
||||||
return handler
|
return handler
|
||||||
|
|
|
@ -803,6 +803,21 @@ def test_static_add_route(app, strict_slashes):
|
||||||
assert response.text == "OK2"
|
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):
|
def test_dynamic_add_route(app):
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user