Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions starlette/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import typing
from email.utils import formatdate
from mimetypes import guess_type as mimetypes_guess_type
from urllib.parse import quote, quote_plus
from urllib.parse import quote

from starlette.background import BackgroundTask
from starlette.concurrency import iterate_in_threadpool, run_until_first_complete
Expand Down Expand Up @@ -178,7 +178,7 @@ def __init__(
super().__init__(
content=b"", status_code=status_code, headers=headers, background=background
)
self.headers["location"] = quote_plus(str(url), safe=":/%#?&=@[]!$&'()*+,;")
self.headers["location"] = quote(str(url), safe=":/%#?=@[]!$&'()*+,;")


class StreamingResponse(Response):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ async def app(scope, receive, send):
assert response.url == "http://testserver/"


def test_quoting_redirect_response():
async def app(scope, receive, send):
if scope["path"] == "/I ♥ Starlette/":
response = Response("hello, world", media_type="text/plain")
else:
response = RedirectResponse("/I ♥ Starlette/")
await response(scope, receive, send)

client = TestClient(app)
response = client.get("/redirect")
assert response.text == "hello, world"
assert response.url == "http://testserver/I%20%E2%99%A5%20Starlette/"


def test_streaming_response():
filled_by_bg_task = ""

Expand Down