Skip to content
Open
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
11 changes: 7 additions & 4 deletions src/flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from itertools import chain
from types import TracebackType
from urllib.parse import quote as _url_quote
from urllib.parse import urlsplit

import click
from werkzeug.datastructures import Headers
Expand Down Expand Up @@ -635,7 +636,9 @@ def run(
sn_host = sn_port = None

if server_name:
sn_host, _, sn_port = server_name.partition(":")
server_url = urlsplit(f"//{server_name}")

@lkk7 lkk7 Jul 14, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added "//" to make urlsplit work in this instance. I assume that this won't break anything, but you definitely know more about that.

sn_host = server_url.hostname
sn_port = server_url.port

if not host:
if sn_host:
Expand All @@ -645,8 +648,8 @@ def run(

if port or port == 0:
port = int(port)
elif sn_port:
port = int(sn_port)
elif sn_port is not None:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sn_port changed to int/none, that's the reason for this change

port = sn_port
else:
port = 5000

Expand All @@ -659,7 +662,7 @@ def run(
from werkzeug.serving import run_simple

try:
run_simple(t.cast(str, host), port, self, **options)
run_simple(host, port, self, **options)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mypy: Redundant cast to "str"

finally:
# reset the first request information if the development server
# reset normally. This makes it possible to restart the server
Expand Down
2 changes: 1 addition & 1 deletion src/flask/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def session_transaction(
app.session_interface.save_session(app, sess, resp)

self._update_cookies_from_response(
ctx.request.host.partition(":")[0],
urlsplit(ctx.request.host_url).hostname or "localhost",

@lkk7 lkk7 Jul 14, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the part I was unsure about.
Hostname can be None, so I used the behavior from the werkzeug change you mentioned:

hostname = url.hostname or "localhost"

ctx.request.path,
resp.headers.getlist("Set-Cookie"),
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,7 @@ def run_simple_mock(hostname, port, application, *args, **kwargs):
("localhost", 0, "localhost:8080", "localhost", 0),
(None, None, "localhost:8080", "localhost", 8080),
(None, None, "localhost:0", "localhost", 0),
(None, None, "[::1]:8080", "::1", 8080),
),
)
def test_run_from_config(
Expand Down
14 changes: 14 additions & 0 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@ def index():
assert sess["foo"] == [42]


def test_session_transaction_ipv6(app):
base_url = "http://[::1]:8000/"
client = app.test_client()

@app.get("/")
def index():
return str(flask.session.get("value"))

with client.session_transaction(base_url=base_url) as sess:
sess["value"] = 42

assert client.get("/", base_url=base_url).text == "42"


def test_session_transactions_no_null_sessions():
app = flask.Flask(__name__)

Expand Down
Loading