Skip to content

Commit 21d971a

Browse files
mdelaneyMatt Delaney
authored andcommitted
Fixed host parsing to work with ipv6 addresses
can now put [ ] around the ip address, without this ipv6 addresses that are like 2605:fd00:4:1000:f816:3eff:fe33:4679 would be have '4679' be interpreted as a port number.
1 parent 5b668d5 commit 21d971a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/net/ssh/multi/server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def initialize(master, host, options={})
4444
@master = master
4545
@options = options.dup
4646

47-
@user, @host, port = host.match(/^(?:([^;,:=]+)@|)(.*?)(?::(\d+)|)$/)[1,3]
47+
@user, @host, port = host.match(/^(?:([^;,:=]+)@|)\[?(.*?)\]?(?::(\d+)|)$/)[1,3]
4848

4949
user_opt, port_opt = @options.delete(:user), @options.delete(:port)
5050

test/server_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def test_accessor_with_properties_should_access_properties
1414
assert_equal "hello", server('host', :properties => { :foo => "hello" })[:foo]
1515
end
1616

17+
def test_ipv6_works_with_given_port_using_bracket_notation
18+
assert_equal 9022, server('[2001:DB8::1234]:9022').port
19+
end
20+
1721
def test_port_should_return_22_by_default
1822
assert_equal 22, server('host').port
1923
end

0 commit comments

Comments
 (0)