Repository navigation
Handle unbracketed ipv6 addresses - #538
Conversation
Instead of having 2 separate parsers
mattbrictson
left a comment
There was a problem hiding this comment.
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=nilIs 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 |
| end | ||
|
|
||
| def test_custom_host_with_port | ||
| h = Host.new 'db:22' |
There was a problem hiding this comment.
✨ 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::Regexfrom 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::Regexinstead, which should prove more stable. I added an extra unit test to validate the local hostname scenario.