Skip to content

Fix `.partition(":") usage on potential IPv6 addresses#6096

Open
lkk7 wants to merge 2 commits into
pallets:stablefrom
lkk7:fix-partition-usage
Open

Fix `.partition(":") usage on potential IPv6 addresses#6096
lkk7 wants to merge 2 commits into
pallets:stablefrom
lkk7:fix-partition-usage

Conversation

@lkk7

@lkk7 lkk7 commented Jul 14, 2026

Copy link
Copy Markdown

Fix two usages of .partition(":") on potential IPv6 addresses.
Replace them with alternatives.

Fixes #6093

Comment thread src/flask/app.py
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

Comment thread src/flask/app.py

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"

Comment thread src/flask/testing.py

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"

Comment thread src/flask/app.py

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.

@lkk7

lkk7 commented Jul 14, 2026

Copy link
Copy Markdown
Author

Not sure about the reason of "Development Versions" fail...

@davidism

davidism commented Jul 14, 2026

Copy link
Copy Markdown
Member

Dev tests are not updated for Werkzeug main yet, they're expected to fail until next Werkzeug release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants