1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Merge pull request #1954 from rjwalsh88/fix-host-filter-regex

HostFilter: Fix regex for multi-host strings
This commit is contained in:
Matt Brictson 2017-11-27 15:30:49 -08:00 committed by GitHub
commit cb25fa9b41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View file

@ -20,6 +20,10 @@ gem "capistrano", :github => "capistrano/capistrano"
* Your contribution here!
### Fixes:
* [#1954](https://github.com/capistrano/capistrano/pull/1954): Fix Host filtering when multi-host strings contain `0`
## [`3.10.0`] (2017-10-23)
[`3.10.0`]: https://github.com/capistrano/capistrano/compare/v3.9.1...v3.10.0

View file

@ -3,7 +3,7 @@ module Capistrano
class HostFilter
def initialize(values)
av = Array(values).dup
av = av.flat_map { |v| v.is_a?(String) && v =~ /^(?<name>[-A-Za-z1-9.]+)(,\g<name>)*$/ ? v.split(",") : v }
av = av.flat_map { |v| v.is_a?(String) && v =~ /^(?<name>[-A-Za-z0-9.]+)(,\g<name>)*$/ ? v.split(",") : v }
@rex = regex_matcher(av)
end

View file

@ -10,7 +10,7 @@ module Capistrano
Server.new("server2"),
Server.new("server3"),
Server.new("server4"),
Server.new("server5")]
Server.new("server10")]
end
shared_examples "it filters hosts correctly" do |expected|
@ -32,8 +32,8 @@ module Capistrano
end
context "with a comma separated string" do
let(:values) { "server1,server3" }
it_behaves_like "it filters hosts correctly", %w{server1 server3}
let(:values) { "server1,server10" }
it_behaves_like "it filters hosts correctly", %w{server1 server10}
end
context "with an array of strings" do
@ -53,12 +53,12 @@ module Capistrano
context "with a regexp with line boundaries" do
let(:values) { "^server" }
it_behaves_like "it filters hosts correctly", %w{server1 server2 server3 server4 server5}
it_behaves_like "it filters hosts correctly", %w{server1 server2 server3 server4 server10}
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}
it_behaves_like "it filters hosts correctly", %w{server1 server2 server3 server4 server10}
end
context "without number" do