lib/fulmar/infrastructure/service/ssh_config_service.rb in fulmar-2.2.2 vs lib/fulmar/infrastructure/service/ssh_config_service.rb in fulmar-2.2.3

- old
+ new

@@ -53,11 +53,11 @@ def remove_known_host(hostname) input_file = File.open(@known_hosts_file, 'r') output_file = File.open(@known_hosts_file + '.temp', 'w') while (line = input_file.gets) - output_file.puts(line) unless /^\[?#{hostname.gsub('.', '\\.')}(?:\]:\d+)?[ ,]/ =~ line + output_file.puts(line) unless /^\[?#{Regexp.escape(hostname)}(?:\]:\d+)?[ ,]/ =~ line end input_file.close output_file.close FileUtils.mv(@known_hosts_file + '.temp', @known_hosts_file) end @@ -75,11 +75,11 @@ # Parses the users ssh config for an existing hostname def host_exists?(hostname) config_file = File.open(@config_file, 'r') while (line = config_file.gets) - if /\s*Host #{hostname.gsub('.', '\\.')}\s*$/ =~ line + if /\s*Host #{Regexp.escape(hostname)}\s*$/ =~ line config_file.close return true end end config_file.close @@ -151,20 +151,20 @@ before = [] data.each do |line| if line.strip[0] == '#' cache << line else - return remove_trailing_newlines(before) if /^Host\s#{hostname}$/ =~ line.strip + return remove_trailing_newlines(before) if /^Host\s#{Regexp.escape(hostname)}$/ =~ line.strip before += cache cache = [] before << line end end remove_trailing_newlines(before) end def block_after(data, hostname) - data = data.drop_while { |i| !/^Host\s#{hostname}$/.match(i.strip) } + data = data.drop_while { |i| !/^Host\s#{Regexp.escape(hostname)}$/.match(i.strip) } return [] if data.empty? data.shift after = [] cache = []