-
Notifications
You must be signed in to change notification settings - Fork 177
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
Dangling section headers persist in INI files when sections contain whitespace #524
Comments
As discussed here, I think that auto-pruning empty sections is beyond the scope of the My proposal would be to remove the auto-removing of empty sections from ini_section { 'section1':
ensure => absent,
} @peytonw1 would this allow you to do what you want? |
In order to explicitly manage sections of an ini file regardless of their content, we introduce a new ini_section type. This make it possible to remove a whole section of an ini file, regardless of its content: ```puppet ini_section { 'remove puppet.conf agent section': ensure => abent, path => '/etc/puppetlabs/puppet/puppet.conf', section => 'agent', } ``` Just like the ini_setting type, ini_section can be subclassed: ```puppet puppet_config { 'remove agent section': ensure => abent, section => 'agent', } ``` Fixes #524
In order to explicitly manage sections of an ini file regardless of their content, we introduce a new ini_section type. This make it possible to remove a whole section of an ini file, regardless of its content: ```puppet ini_section { 'remove puppet.conf agent section': ensure => abent, path => '/etc/puppetlabs/puppet/puppet.conf', section => 'agent', } ``` Just like the ini_setting type, ini_section can be subclassed: ```puppet puppet_config { 'remove agent section': ensure => abent, section => 'agent', } ``` Fixes #524
In order to explicitly manage sections of an ini file regardless of their content, we introduce a new ini_section type. This make it possible to remove a whole section of an ini file, regardless of its content: ```puppet ini_section { 'remove puppet.conf agent section': ensure => abent, path => '/etc/puppetlabs/puppet/puppet.conf', section => 'agent', } ``` Just like the ini_setting type, ini_section can be subclassed: ```puppet puppet_config { 'remove agent section': ensure => abent, section => 'agent', } ``` Fixes #524
In order to explicitly manage sections of an ini file regardless of their content, we introduce a new ini_section type. This make it possible to remove a whole section of an ini file, regardless of its content: ```puppet ini_section { 'remove puppet.conf agent section': ensure => abent, path => '/etc/puppetlabs/puppet/puppet.conf', section => 'agent', } ``` Just like the ini_setting type, ini_section can be subclassed: ```puppet puppet_config { 'remove agent section': ensure => abent, section => 'agent', } ``` Fixes #524
@smortex yes that would, thanks! |
@peytonw1 cool! There was some discussion here in case you missed it, with links to PR that fix the issue: |
In order to explicitly manage sections of an ini file regardless of their content, we introduce a new ini_section type. This make it possible to remove a whole section of an ini file, regardless of its content: ```puppet ini_section { 'remove puppet.conf agent section': ensure => abent, path => '/etc/puppetlabs/puppet/puppet.conf', section => 'agent', } ``` Just like the ini_setting type, ini_section can be subclassed: ```puppet puppet_config { 'remove agent section': ensure => abent, section => 'agent', } ``` Fixes #524
Describe the Bug
When removing the only setting in a section, the section header still remains when the section contains whitespace. As a result, trailing section headers (i.e. sections without any settings) will persist in INI files like below and eventually cause unnecessary clutter:
Expected Behavior
We would expect to see section headers to be removed when we are removing the last and only setting in a section.
Steps to Reproduce
Here is an example of a section with a singular setting, in which the empty section header still remains upon ensuring the setting is absent:
/tmp/test.ini
,/tmp/test_remove_setting.pp
) as shown below, in which we aimed to removesetting1
and the[section1]
header:setting1
was removed, the[section1]
header still persisted:However, when removing the newline after
setting1
, both the setting AND section header are removed correctly:test.ini
to not include a newline after the first setting:setting1
and the[section1]
header are removed as expected:Environment
Additional Context
We also stepped through the puppetlabs-inifile code with
pry
to observe theIniFile::Section
object in the reproduced problem (steps 1-3 above). Initially, we saw thatsection1
consisted of@start_line=0
and@end_line=2
.The start and end lines correspond to the lines with the
[section1]
header and the newline before the[section2]
header, respectively, in thetest.ini
file:After removing
setting1
, we observed inremove_setting()
that the section was not registered as empty.However, looking at the final state of the
Puppet::Util::IniFile::Section
object, we saw thatsection1
now had@start_line=0
and@end_line=1
.Furthermore, in the section.rb code here, the
section.empty?
function returns true if the section'sstart_line == end_line
. Thus, this shows that sections containing whitespace are not getting removed correctly, as the code counts the whitespace in the start and end lines to determine if the section is empty.The text was updated successfully, but these errors were encountered: