From de6dc5f9e054155a6efff38093391b8dbe87d5f0 Mon Sep 17 00:00:00 2001 From: Tom Andrew Date: Fri, 23 Jul 2021 13:56:12 +0100 Subject: [PATCH] match section names containing prefix character 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. --- lib/puppet/util/ini_file.rb | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index 15c2dbef..2eaf401a 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -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}}