Skip to content

Commit 42cfdb1

Browse files
committed
(CAT-1646) - Remove section if its not have any settings
1 parent 94a3c57 commit 42cfdb1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/puppet/util/ini_file.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def parse_file
220220
def read_section(name, start_line, line_iter)
221221
settings = {}
222222
end_line_num = start_line
223+
previous_line = nil
223224
min_indentation = nil
224225
empty = true
225226
loop do
@@ -229,14 +230,22 @@ def read_section(name, start_line, line_iter)
229230
# when it's empty, we must be sure it's thought of as new,
230231
# which is signalled with a nil ending line
231232
end_line_num = nil if name == '' && empty
233+
end_line_num = line_num - 1 if previous_line == "\n"
232234
return Section.new(name, start_line, end_line_num, settings, min_indentation)
233235
end
234236
if (match = @setting_regex.match(line))
235237
settings[match[2]] = match[4]
236238
indentation = match[1].length
237239
min_indentation = [indentation, min_indentation || indentation].min
238240
end
239-
end_line_num = line_num
241+
# If we have a comment line, we need to remember it so that
242+
# we can insert new settings *before* the comment line.
243+
if line != "\n"
244+
end_line_num = line_num
245+
previous_line = nil
246+
else
247+
previous_line = line
248+
end
240249
empty = false
241250
line_iter.next
242251
end

0 commit comments

Comments
 (0)