diff --git a/CHANGELOG.md b/CHANGELOG.md index bc7088c3..924f95c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ https://github.com/capistrano/capistrano/compare/v3.6.1...HEAD * Your contribution here! * `remote_file` feature has been removed and is no longer available to use @SaiVardhan -* fix bug with greedy matching in host_filter [#1766](https://github.com/capistrano/capistrano/issues/1766) (@cseeger-epages) +* Fix bug where host_filter and role_filter were overly greedy [#1766](https://github.com/capistrano/capistrano/issues/1766) (@cseeger-epages) ## `3.6.1` (2016-08-23) diff --git a/lib/capistrano/configuration/role_filter.rb b/lib/capistrano/configuration/role_filter.rb index 5157e32c..50270554 100644 --- a/lib/capistrano/configuration/role_filter.rb +++ b/lib/capistrano/configuration/role_filter.rb @@ -20,7 +20,7 @@ module Capistrano when Regexp then v else vs = v.to_s - vs =~ %r{^/(.+)/$} ? Regexp.new($1) : /^#{vs}$/ + vs =~ %r{^/(.+)/$} ? Regexp.new($1) : /^#{Regexp.quote(vs)}$/ end end Regexp.union values diff --git a/spec/lib/capistrano/configuration/role_filter_spec.rb b/spec/lib/capistrano/configuration/role_filter_spec.rb index aa3173c9..1eca4788 100644 --- a/spec/lib/capistrano/configuration/role_filter_spec.rb +++ b/spec/lib/capistrano/configuration/role_filter_spec.rb @@ -11,7 +11,8 @@ module Capistrano Server.new("server2").add_role(:web), Server.new("server3").add_role(:redis), Server.new("server4").add_role(:db), - Server.new("server5").add_role(:stageweb) + Server.new("server5").add_role(:stageweb), + Server.new("server6").add_role(:"db.new") ] end @@ -58,6 +59,21 @@ module Capistrano let(:values) { "db,/red/" } it_behaves_like "it filters roles correctly", 3, %w{server1 server3 server4} end + + context "with a dot wildcard" do + let(:values) { "db.*" } + it_behaves_like "it filters roles correctly", 0, %w{} + end + + context "with a dot" do + let(:values) { "db.new" } + it_behaves_like "it filters roles correctly", 1, %w{server6} + end + + context "with a dot wildcard regex" do + let(:values) { "/db.*/" } + it_behaves_like "it filters roles correctly", 3, %w{server1 server4 server6} + end end end end