question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] `+` (plus) in get parameters is converted to ` ` (space)

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
euri10commented, Nov 20, 2019

that said, after some ressearch, your usecase is incorrect @jorgecarleitao , the plus sign like the & has a meaning in a query string and is used to represent a space, hence why urllib does what it does, you can read more on https://stackoverflow.com/questions/1005676/does-a-in-a-url-scheme-host-path-represent-a-space

0reactions
tiangolocommented, Apr 10, 2020

Thanks for the help here @euri10 ! 👏 🙇

Thanks for reporting back and closing the issue @jorgecarleitao 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular url plus sign converting to space - Stack Overflow
@Maximus I tried to decode and use it. I am getting space ` ` instead of +. There is an old version of...
Read more >
Request #39078 :: Plus sign in URL arg received as space
This is a simple case using default configurations where a client JavaScript script sends a plus sign and a space as an argument...
Read more >
URLEncoding of spaces in query parameters + vs %20
My problem is that any space is automatically encoded as a + and not as %20. While it is not necessarily wrong for...
Read more >
HTTP Request with Plus Sign "+" in Query Param is Converted ...
SYMPTOM. When receiving HTTP request using HTTP Listener, the HTTP connector converts "+" sign within the query parameter to space. · CAUSE. In ......
Read more >
URL from string with spaces in it | Apple Developer Forums
I'm getting errors in a Swift script if a filepath uses spaces. (The filepath gets converted to a URL.) I've got a workaround:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found