AI junk - #6115
Closed
DijieDeng wants to merge 1 commit into
Closed
Conversation
Replace `.partition(":")[0]` with `urlsplit(ctx.request.host_url).hostname`
to correctly handle IPv6 addresses which contain multiple colons.
Fixes pallets#6093 (testing.py part)
Member
|
This appears LLM-generated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix IPv6 address parsing in
session_transactionFixes part of #6093.
Problem
Two places in Flask use
.partition(":")to parse host:port strings, but IPv6 addresses like[::1]:8000contain multiple colons, so.partition(":")splits at the wrong position:session_transactioninsrc/flask/testing.py—ctx.request.host.partition(":")[0]returns"["instead of"[::1]"for IPv6 hosts. This breaks cookie domain extraction during session transactions with IPv6 base URLs.Flask.run()insrc/flask/app.py—server_name.partition(":")incorrectly parsesSERVER_NAMEwhen it contains an IPv6 address (e.g.,[::1]:8080).Fix applied in this PR (testing.py)
Replaced
ctx.request.host.partition(":")[0]withurlsplit(ctx.request.host_url).hostname or "localhost". Thehost_urlproperty includes the scheme (e.g.,http://[::1]:8000), sourlsplitcan correctly parse the hostname from IPv6 addresses. Theurlsplitimport already exists intesting.py.Fix still needed (app.py)
The
run()method insrc/flask/app.pyalso needs the same fix. The change would be:This follows the same approach used in the Werkzeug fix for the same issue.
Test added
Added
test_session_transaction_ipv6totests/test_testing.pywhich verifies that session transactions work correctly with IPv6 base URLs:This test fails without the fix (raises an error or returns incorrect results) and passes with the fix.