Skip to content

+ (plus) in get parameters is converted to (space) #720

@jorgecarleitao

Description

@jorgecarleitao

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'.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions