diff options
author | Lee Marlow <lee.marlow@gmail.com> | 2010-04-13 04:34:55 +0800 |
---|---|---|
committer | <net-ssh@solutious.com> | 2010-04-21 04:13:53 +0800 |
commit | a528bc3b46222b2f480da75606e4fd0754673629 (patch) | |
tree | 26df4d4b6362c51ef4f65415277793e8c26b9237 | |
parent | 54388c2ce032e12e287274815a50235214c88f56 (diff) | |
download | net-ssh-a528bc3b46222b2f480da75606e4fd0754673629.tar.gz |
Allow host aliases to be numeric when parsing ssh_config files
A host with a numeric alias would raise an error because it was coerced
into an integer before trying to split it by spaces when trying to
handle multiple hosts.
For example:
Host 1
Hostname my.favoritehost.com
-rw-r--r-- | lib/net/ssh/config.rb | 2 | ||||
-rw-r--r-- | test/configs/numeric_host | 4 | ||||
-rw-r--r-- | test/test_config.rb | 7 |
3 files changed, 12 insertions, 1 deletions
diff --git a/lib/net/ssh/config.rb b/lib/net/ssh/config.rb index 1ced224..6eb9c2e 100644 --- a/lib/net/ssh/config.rb +++ b/lib/net/ssh/config.rb @@ -88,7 +88,7 @@ module Net; module SSH if key == 'host' # Support "Host host1 host2 hostN". # See http://github.com/net-ssh/net-ssh/issues#issue/6 - multi_host = value.split(/\s+/) + multi_host = value.to_s.split(/\s+/) matched_host = multi_host.select { |h| host =~ pattern2regex(h) }.first seen_host = true elsif !seen_host diff --git a/test/configs/numeric_host b/test/configs/numeric_host new file mode 100644 index 0000000..cf75e50 --- /dev/null +++ b/test/configs/numeric_host @@ -0,0 +1,4 @@ +Host 1234 + Compression yes + Port 1980 + RekeyLimit 2G diff --git a/test/test_config.rb b/test/test_config.rb index 37e6eba..361c067 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -102,6 +102,13 @@ class TestConfig < Test::Unit::TestCase assert config['compression'] end + def test_load_with_numeric_host + config = Net::SSH::Config.load(config(:numeric_host), "1234") + assert config['compression'] + assert_equal '2G', config['rekeylimit'] + assert_equal 1980, config['port'] + end + private def config(name) |