-
Notifications
You must be signed in to change notification settings - Fork 254
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
Handle unbracketed ipv6 addresses #538
Handle unbracketed ipv6 addresses #538
Conversation
Instead of having 2 separate parsers
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.
Thanks for the PR! Sorry for the slow response.
I think the ambiguity in the IPv6 regex means that moving it up in the parser priority will introduce problems. For example, there a regression when the hostname is "db" and a port is specified:
# Expected behavior
Host.new("db:22")
# => hostname="db", port=22
# Regression
Host.new("db:22")
# => hostname="db:22", port=nil
Is there a way to make the regex more strict to solve this? I am not very familiar with IPv6 addresses, so I'm not sure I can offer a solution, other than to stick with the status-quo []
requirement.
Maybe using Resolv::IPv6::Regex
(as you originally implemented) is the way to go?
@mattbrictson Good point. Because the IPv6 parser still needs a high priority, we need a strict IPv6 regex. I have updated the PR and description accordingly, and added an extra unit test for the |
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.
Looks great!
@@ -28,6 +28,12 @@ def test_host_with_port | |||
assert_equal 'example.com', h.hostname | |||
end | |||
|
|||
def test_custom_host_with_port | |||
h = Host.new 'db:22' |
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.
✨ Thanks for the additional test!
Set sshkit minimum version to 1.23.0, which includes an enhancement to support unbracketed IPv6 addresses. See capistrano/sshkit#538
Set sshkit minimum version to 1.23.0, which includes an enhancement to support unbracketed IPv6 addresses. See capistrano/sshkit#538
Fix for #537.
Solution
IPv6HostParser
. This parser has a high priority in the parser list so IPv6 addresses are not incorrectly picked up and parsed byHostWithPortParser
's simple regex.Resolv::IPv6::Regex
from the stdlib.Notes
My previous solution tweaked the regex of the existing
IPv6HostWithPortParser
, but this resulted in a regression for local hostnames, so I am usingResolv::IPv6::Regex
instead, which should prove more stable. I added an extra unit test to validate the local hostname scenario.