[BUG] `+` (plus) in get parameters is converted to ` ` (space)
See original GitHub issueTo 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:
- https://www.w3schools.com/tags/ref_urlencode.asp
- https://stackoverflow.com/questions/1005676/does-a-in-a-url-scheme-host-path-represent-a-space
Current workaround:
pass the url-encoded version of the + to the test client: '%2B'
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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-spaceThanks for the help here @euri10 ! 👏 🙇
Thanks for reporting back and closing the issue @jorgecarleitao 👍