Skip to content

Commit

Permalink
Merge pull request #1578 from cshaffer/fix-host-filter-bug
Browse files Browse the repository at this point in the history
Fix host filter regression
  • Loading branch information
mattbrictson committed Feb 5, 2016
2 parents 7c061db + 5388442 commit 4099f0f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
18 changes: 14 additions & 4 deletions lib/capistrano/configuration/host_filter.rb
@@ -1,10 +1,6 @@
require 'capistrano/configuration/regex_filter'

module Capistrano
class Configuration
class HostFilter
include RegexFilter

def initialize values
av = Array(values).dup
av.map! { |v| (v.is_a?(String) && v =~ /^(?<name>[-A-Za-z0-9.]+)(,\g<name>)*$/) ? v.split(',') : v }
Expand All @@ -15,6 +11,20 @@ def initialize values
def filter servers
Array(servers).select { |s| @rex.match s.to_s }
end

private

def regex_matcher(values)
values.map! do |v|
case v
when Regexp then v
else
vs = v.to_s
vs =~ /^[-A-Za-z0-9.]+$/ ? vs : Regexp.new(vs)
end
end
Regexp.union values
end
end
end
end
17 changes: 0 additions & 17 deletions lib/capistrano/configuration/regex_filter.rb

This file was deleted.

18 changes: 14 additions & 4 deletions lib/capistrano/configuration/role_filter.rb
@@ -1,10 +1,6 @@
require 'capistrano/configuration/regex_filter'

module Capistrano
class Configuration
class RoleFilter
include RegexFilter

def initialize values
av = Array(values).dup
av.map! { |v| v.is_a?(String) ? v.split(',') : v }
Expand All @@ -15,6 +11,20 @@ def initialize values
def filter servers
Array(servers).select { |s| s.is_a?(String) ? false : s.roles.any? { |r| @rex.match r } }
end

private

def regex_matcher(values)
values.map! do |v|
case v
when Regexp then v
else
vs = v.to_s
vs =~ %r{^/(.+)/$} ? Regexp.new($1) : %r{^#{vs}$}
end
end
Regexp.union values
end
end
end
end
5 changes: 5 additions & 0 deletions spec/lib/capistrano/configuration/host_filter_spec.rb
Expand Up @@ -44,6 +44,11 @@ class Configuration
it_behaves_like 'it filters hosts correctly', %w{server1 server3}
end

context 'with a regexp with line boundaries' do
let(:values) { '^server' }
it_behaves_like 'it filters hosts correctly', %w{server1 server2 server3 server4 server5}
end

context 'with a regexp with a comma' do
let(:values) { 'server\d{1,3}$' }
it_behaves_like 'it filters hosts correctly', %w{server1 server2 server3 server4 server5}
Expand Down

0 comments on commit 4099f0f

Please sign in to comment.