Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-11429) Make split() sensitive-aware #9118

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion lib/puppet/functions/split.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
param 'Type[Regexp]', :pattern
end

dispatch :split_String_sensitive do
param 'Sensitive[String]', :sensitive
param 'String', :pattern
end

dispatch :split_Regexp_sensitive do
param 'Sensitive[String]', :sensitive
param 'Regexp', :pattern
end

dispatch :split_RegexpType_sensitive do
param 'Sensitive[String]', :sensitive
param 'Type[Regexp]', :pattern
end

def split_String(str, pattern)
str.split(Regexp.compile(pattern))
end
Expand All @@ -46,4 +61,16 @@ def split_Regexp(str, pattern)
def split_RegexpType(str, pattern)
str.split(pattern.regexp)
end
end

def split_String_sensitive(sensitive, pattern)
Puppet::Pops::Types::PSensitiveType::Sensitive.new(split_String(sensitive.unwrap, pattern))
end

def split_Regexp_sensitive(sensitive, pattern)
Puppet::Pops::Types::PSensitiveType::Sensitive.new(split_Regexp(sensitive.unwrap, pattern))
end

def split_RegexpType_sensitive(sensitive, pattern)
Puppet::Pops::Types::PSensitiveType::Sensitive.new(split_RegexpType(sensitive.unwrap, pattern))
end
end
6 changes: 6 additions & 0 deletions spec/unit/functions/split_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ def split(*args)
it 'should handle pattern in Regexp Type form with missing regular expression' do
expect(split('ab',type_parser.parse('Regexp'))).to eql(['a', 'b'])
end

it 'should handle sensitive String' do
expect(split(Puppet::Pops::Types::PSensitiveType::Sensitive.new('a,b'), ',')).to be_a(Puppet::Pops::Types::PSensitiveType::Sensitive)
expect(split(Puppet::Pops::Types::PSensitiveType::Sensitive.new('a,b'), /,/)).to be_a(Puppet::Pops::Types::PSensitiveType::Sensitive)
expect(split(Puppet::Pops::Types::PSensitiveType::Sensitive.new('a,b'), type_parser.parse('Regexp[/,/]'))).to be_a(Puppet::Pops::Types::PSensitiveType::Sensitive)
end
end