Skip to content

Fix use_proxy? to correctly handle IPv6 addresses in no_proxy#219

Open
rodrigotomonari wants to merge 1 commit intoruby:masterfrom
rodrigotomonari:fix-use-proxy-ipv6-no-proxy
Open

Fix use_proxy? to correctly handle IPv6 addresses in no_proxy#219
rodrigotomonari wants to merge 1 commit intoruby:masterfrom
rodrigotomonari:fix-use-proxy-ipv6-no-proxy

Conversation

@rodrigotomonari
Copy link
Copy Markdown

The previous regex-based scan fragmented IPv6 addresses on colons, causing all IPv6 no_proxy entries to be silently ignored.

Replace scan with split-then-branch parsing that handles four formats:

  • Bare IPv6: 2001:db8::1, 2001:db8::/32
  • Bracketed: [2001:db8::1]
  • Bracketed with port: [2001:db8::1]:8080
  • IPv4/hostname: example.com, 10.0.0.1:8080, example.com: (trailing colon)

Also strips zone IDs (e.g. ::1%eth0) before IPAddr matching, and reads $2 before calling sub() to avoid global match variable clobbering.

Fixes #218

The previous regex-based scan fragmented IPv6 addresses on colons,
causing all IPv6 no_proxy entries to be silently ignored.

Replace scan with split-then-branch parsing that handles four formats:
- Bare IPv6:           2001:db8::1, 2001:db8::/32
- Bracketed:           [2001:db8::1]
- Bracketed with port: [2001:db8::1]:8080
- IPv4/hostname:       example.com, 10.0.0.1:8080, example.com: (trailing colon)

Also strips zone IDs (e.g. ::1%eth0) before IPAddr matching, and
reads $2 before calling sub() to avoid global match variable clobbering.

Fixes ruby#218
begin
return false if IPAddr.new(p_host).include?(addr)
rescue IPAddr::InvalidAddressError
next
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.

The next in the rescue IPAddr::InvalidAddressError clause was removed as it is redundant. Falling off the end of the block body advances to the next iteration identically to calling next explicitly. No behavioral change.

@stanhu
Copy link
Copy Markdown

stanhu commented Apr 6, 2026

@hsbt Would you mind taking a look at this?

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.

URI::Generic.use_proxy? cannot match IPv6 literal addresses in no_proxy

3 participants