diff options
author | John Keiser <john@johnkeiser.com> | 2015-07-29 17:25:20 -0600 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-07-29 17:25:20 -0600 |
commit | 96053ccb88f145a1f6a354cfe709bc99176723cb (patch) | |
tree | db0ae0c5f8f53b0f2f490d3138c11d192c264a88 | |
parent | 28e20d62f3dcb29f34c2f67b41a1b486108f388d (diff) | |
download | chef-96053ccb88f145a1f6a354cfe709bc99176723cb.tar.gz |
Flatten regex validation array so nested arrays work
-rw-r--r-- | lib/chef/mixin/params_validate.rb | 2 | ||||
-rw-r--r-- | spec/unit/property/validation_spec.rb | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb index 322caea474..1b3a8ddcae 100644 --- a/lib/chef/mixin/params_validate.rb +++ b/lib/chef/mixin/params_validate.rb @@ -291,7 +291,7 @@ class Chef def _pv_regex(opts, key, regex) value = _pv_opts_lookup(opts, key) if !value.nil? - Array(regex).each do |r| + Array(regex).flatten.each do |r| return true if r.match(value.to_s) end raise Exceptions::ValidationFailed, "Option #{key}'s value #{value} does not match regular expression #{regex.inspect}" diff --git a/spec/unit/property/validation_spec.rb b/spec/unit/property/validation_spec.rb index a3649d228c..31bb3f0739 100644 --- a/spec/unit/property/validation_spec.rb +++ b/spec/unit/property/validation_spec.rb @@ -402,6 +402,11 @@ describe "Chef::Resource.property validation" do [ 'gbh', 123 ], [ nil ] + validation_test 'regex: [ [ /z/, /abc/ ], [ /n/ ] ]', + [ 'xabcy', 'aza', 'ana' ], + [ 'gbh', 123 ], + [ nil ] + validation_test 'regex: []', [], [ :a ], |