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

Fix TestClient for extra unquote in query parameters (#1952) #1953

Merged
merged 3 commits into from Nov 16, 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
4 changes: 2 additions & 2 deletions starlette/testclient.py
Expand Up @@ -196,10 +196,10 @@ def __init__(

def handle_request(self, request: httpx.Request) -> httpx.Response:
scheme = request.url.scheme
netloc = unquote(request.url.netloc.decode(encoding="ascii"))
netloc = request.url.netloc.decode(encoding="ascii")
path = request.url.path
raw_path = request.url.raw_path
query = unquote(request.url.query.decode(encoding="ascii"))
query = request.url.query.decode(encoding="ascii")

default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme]

Expand Down
13 changes: 12 additions & 1 deletion tests/test_testclient.py
Expand Up @@ -9,7 +9,7 @@

from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.responses import JSONResponse
from starlette.responses import JSONResponse, Response
from starlette.routing import Route
from starlette.websockets import WebSocket, WebSocketDisconnect

Expand Down Expand Up @@ -240,3 +240,14 @@ async def app(scope, receive, send):
client = test_client_factory(app)
response = client.get("/")
assert response.json() == {"host": "testclient", "port": 50000}


@pytest.mark.parametrize("param", ("2020-07-14T00:00:00+00:00", "España", "voilà"))
def test_query_params(test_client_factory, param: str):
def homepage(request):
return Response(request.query_params["param"])

app = Starlette(routes=[Route("/", endpoint=homepage)])
client = test_client_factory(app)
response = client.get("/", params={"param": param})
assert response.text == param