diff --git a/lib/puppet/functions/regsubst.rb b/lib/puppet/functions/regsubst.rb index 5dde97cb652..5e9bacbc0cb 100644 --- a/lib/puppet/functions/regsubst.rb +++ b/lib/puppet/functions/regsubst.rb @@ -102,7 +102,7 @@ def inner_regsubst(target, re, replacement, op) target.map do |item| inner_regsubst(item, re, replacement, op) end - elsif target.respond_to?(:unwrap) + elsif target.is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive) # this is a Sensitive target = target.unwrap target = target.respond_to?(op) ? target.send(op, re, replacement) : target.map { |e| e.send(op, re, replacement) } diff --git a/spec/unit/functions/regsubst_spec.rb b/spec/unit/functions/regsubst_spec.rb index e818de7b3f1..0750a113826 100644 --- a/spec/unit/functions/regsubst_spec.rb +++ b/spec/unit/functions/regsubst_spec.rb @@ -114,7 +114,9 @@ def regsubst(*args) context 'when using a Target of Type sensitive String' do it 'should process it' do - expect(regsubst(Puppet::Pops::Types::PSensitiveType::Sensitive.new('very secret'), 'very', 'top')).to be_a(Puppet::Pops::Types::PSensitiveType::Sensitive) + result = regsubst(Puppet::Pops::Types::PSensitiveType::Sensitive.new('very secret'), 'very', 'top') + expect(result).to be_a(Puppet::Pops::Types::PSensitiveType::Sensitive) + expect(result.unwrap).to eq("top secret") end end @@ -123,7 +125,9 @@ def regsubst(*args) my_array = ['very down', Puppet::Pops::Types::PSensitiveType::Sensitive.new('very secret')] expect(regsubst(my_array, 'very', 'top')).to be_a(Array) expect(regsubst(my_array, 'very', 'top')[0]).to eq('top down') - expect(regsubst(my_array, 'very', 'top')[1]).to be_a(Puppet::Pops::Types::PSensitiveType::Sensitive) + result = regsubst(my_array, 'very', 'top')[1] + expect(result).to be_a(Puppet::Pops::Types::PSensitiveType::Sensitive) + expect(result.unwrap).to eq('top secret') end end end