To reproduce this:
from starlette.testclient import TestClient
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root(sort: str):
return {'sort': sort}
client = TestClient(app)
response = client.request(url='/?sort=+A', method='GET')
assert response.json()['sort'] == '+A', repr(response.json()['sort'])
# raises exception on my computer, representation on my computer is ' A'
To demonstrate that this is not an issue from starlette:
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.testclient import TestClient
async def app(scope, receive, send):
request = Request(scope, receive)
data = {"method": request.method, "url": str(request.url)}
response = JSONResponse(data)
await response(scope, receive, send)
client = TestClient(app)
response = client.request(url='api/data/?sort=+A', method='GET')
assert response.json()['url'] == 'http://testserver/api/data/?sort=+A'
# no exception on my computer
Python 3.7.3, fastAPI 0.38.0
Other context:
Current workaround:
pass the url-encoded version of the + to the test client: '%2B'.
To reproduce this:
To demonstrate that this is not an issue from starlette:
Python 3.7.3, fastAPI 0.38.0
Other context:
Current workaround:
pass the url-encoded version of the + to the test client:
'%2B'.