Skip to content

AI junk#6094

Closed
abhi-0203 wants to merge 1 commit into
pallets:mainfrom
abhi-0203:fix/ipv6-host-parsing
Closed

AI junk#6094
abhi-0203 wants to merge 1 commit into
pallets:mainfrom
abhi-0203:fix/ipv6-host-parsing

Conversation

@abhi-0203

Copy link
Copy Markdown

Description

Fixes incorrect host parsing for IPv6 addresses in two locations.

Problem

Two places used .partition(":") to split host:port, which breaks for IPv6 addresses like [::1]:8000 because the colon inside the bracket notation is not the host:port separator.

  1. testing.py:180 - ctx.request.host.partition(":")[0] returns [::1 instead of ::1 for IPv6 host headers
  2. app.py:724 - server_name.partition(":") returns [::1 as host and 8000] as port for IPv6 SERVER_NAME

Fix

  • testing.py: Use bracket-aware parsing - if host starts with [, extract hostname between brackets; otherwise use existing partition logic
  • app.py: Use bracket-aware parsing - if server_name starts with [, find the ] bracket and parse port after it; otherwise use existing partition logic

Testing

Added comprehensive test cases covering:

  • IPv4 with port: 127.0.0.1:8000
  • IPv6 with port: [::1]:8000
  • IPv4 without port: localhost
  • IPv6 without port: [::1]
  • IPv6 full address: [2001:db8::1]:8080

All tests pass.

Closes #6093

Two places used .partition(":") to split host:port, which breaks
for IPv6 addresses like [::1]:8000 because the colon inside the
bracket notation is not the host:port separator.

- testing.py: Extract hostname from host header using bracket-aware parsing
- app.py: Parse SERVER_NAME config with bracket-aware host:port splitting

Fixes #6093
@davidism davidism closed this Jul 14, 2026
@davidism davidism changed the title fix: handle IPv6 addresses in host parsing AI junk Jul 14, 2026
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.

IPv6 addresses parsed incorrectly because of .partition(":")?

2 participants