Skip to content

Commit f4c787e

Browse files
authored
Merge pull request #9 from mdelaney/fix_ipv6
Fixed host parsing to work with ipv6 addresses
2 parents 66ab0bb + 21d971a commit f4c787e

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
@@ -45,7 +45,7 @@ def initialize(master, host, options={})
4545
@master = master
4646
@options = options.dup
4747

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

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

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)