Skip to content

Conversation

@mterhar
Copy link
Contributor

@mterhar mterhar commented Jan 12, 2026

Which problem is this PR solving?

IPv6 addresses weren't being found properly, even when UseIPV6Identifier set to true. This is because the To16() call didn't return Nil when an IPv4 address was fed in.

Short description of the changes

This changes the call to use To4() and it skips it on success.

The robust test cases should help avoid a regression as well.

mterhar and others added 2 commits January 12, 2026 20:03
The current implementation incorrectly wraps IPv4 addresses in brackets
when UseIPV6Identifier is true because ip.To16() returns non-nil for
IPv4 addresses (as IPv4-mapped IPv6). This causes invalid URL literals
like "http://[100.122.93.238]:8081".

This commit extracts the IP selection logic into a testable function
and adds test cases that demonstrate the bug.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
ip.To16() returns non-nil for both IPv4 and IPv6 addresses (IPv4
addresses are returned as IPv4-mapped IPv6). This caused IPv4 addresses
to be incorrectly wrapped in brackets when UseIPV6Identifier was true,
resulting in invalid URL literals like "http://[100.122.93.238]:8081".

The fix uses ip.To4() == nil which correctly returns true only for
actual IPv6 addresses.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@mterhar mterhar requested a review from a team as a code owner January 12, 2026 20:06
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