Skip to content

Commit

Permalink
match section names containing prefix character
Browse files Browse the repository at this point in the history
Currently sections with names including the prefix (normally [) can be
created by this provider, but they are then not matched by the regex,
meaning puppet will create a new section (with the same name) every time
it runs. Fix that by allowing the section prefix in the section name.
Any line that starts with the correct prefix (normally [) and ends with
the correct suffix (normally ]) is treated as a valid section header,
regardless of what is between them.

This is needed for splunk inputs.conf file where regexes, including
square brackets, are allowed inside the section name.
  • Loading branch information
tja523 authored and petergmurphy committed May 16, 2022
1 parent a0ef2bd commit de6dc5f
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions lib/puppet/util/ini_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,9 @@ def initialize(path, key_val_separator = ' = ', section_prefix = '[', section_su

def section_regex
# Only put in prefix/suffix if they exist
# Also, if the prefix is '', the negated
# set match should be a match all instead.
r_string = '^\s*'
r_string += Regexp.escape(@section_prefix)
r_string += '('
if @section_prefix != ''
r_string += '[^'
r_string += Regexp.escape(@section_prefix)
r_string += ']'
else
r_string += '.'
end
r_string += '*)'
r_string += '(.*)'
r_string += Regexp.escape(@section_suffix)
r_string += '\s*$'
%r{#{r_string}}
Expand Down

0 comments on commit de6dc5f

Please sign in to comment.