Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use quote instead of quote_plus for RedirectResponse location header #1164

Merged
merged 3 commits into from Apr 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions starlette/responses.py
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
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