Repository navigation
Fix use_proxy? to correctly handle IPv6 addresses in no_proxy #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rodrigotomonari
wants to merge
1
commit into
ruby:master
Choose a base branch
from
rodrigotomonari:fix-use-proxy-ipv6-no-proxy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1582,7 +1582,23 @@ def find_proxy(env=ENV) | |
| def self.use_proxy?(hostname, addr, port, no_proxy) # :nodoc: | ||
| hostname = hostname.downcase | ||
| dothostname = ".#{hostname}" | ||
| no_proxy.scan(/([^:,\s]+)(?::(\d+))?/) {|p_host, p_port| | ||
| no_proxy.split(/[,\s]+/).each {|entry| | ||
| next if entry.empty? | ||
| # Bracketed IPv6: [addr] or [addr]:port | ||
| if entry =~ /\A\[([^\]]+)\](?::(\d+))?\z/ | ||
| p_port = $2 # read $2 before sub() clobbers global match variables | ||
| p_host = $1.sub(/%.*\z/, '') # strip zone ID (e.g. [::1%eth0] -> ::1) | ||
| # Bare IPv6: address contains more than one colon (e.g. 2001:db8::1 or 2001:db8::/32) | ||
| elsif entry.count(':') > 1 | ||
| p_host = entry.sub(/%.*\z/, '') # strip zone ID (e.g. ::1%eth0 -> ::1) | ||
| p_port = nil | ||
| # IPv4 or hostname with optional port (trailing colon treated as no port) | ||
| elsif entry =~ /\A([^:]+)(?::(\d+)?)?\z/ | ||
| p_host = $1 | ||
| p_port = ($2 && !$2.empty?) ? $2 : nil | ||
| else | ||
| next | ||
| end | ||
| if !p_port || port == p_port.to_i | ||
| if p_host.start_with?('.') | ||
| return false if hostname.end_with?(p_host.downcase) | ||
|
|
@@ -1593,7 +1609,6 @@ def self.use_proxy?(hostname, addr, port, no_proxy) # :nodoc: | |
| begin | ||
| return false if IPAddr.new(p_host).include?(addr) | ||
| rescue IPAddr::InvalidAddressError | ||
| next | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| end | ||
| end | ||
| end | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for commenting on such an old PR.
Is the removal of zone IDs necessary? Since net-http and open-uri currently do not support URLs with a zone ID, it probably doesn't matter for now, but I feel it might get in the way if they support it in the future. Also, I'm concerned that
sub(/%.*\z/, '')turnsfe80::%eth0/64intofe80::(the/64is removed as well).I'm not very familiar with this area, so sorry if I'm missing something. I'd appreciate a review from @akr as well.