Skip to content

Commit c784253

Browse files
author
Mike Dorman
committed
MODULES-1599 Match only on space and tab whitespace after k/v separator
The previous match for \s would also match on newlines. This caused existing settings with blank values to have the newline considered part of the whitespace surrounding the separator. When such settings are set with a value, the value ends up on the next line. Also adding acceptance test for this particular situation.
1 parent e132445 commit c784253

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

lib/puppet/util/ini_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize(path, key_val_separator = ' = ', section_prefix = '[', section_su
1313
@section_suffix = section_suffix
1414

1515
@@SECTION_REGEX = section_regex
16-
@@SETTING_REGEX = /^(\s*)([^#;\s]|[^#;\s].*?[^\s#{k_v_s}])(\s*#{k_v_s}\s*)(.*)\s*$/
16+
@@SETTING_REGEX = /^(\s*)([^#;\s]|[^#;\s].*?[^\s#{k_v_s}])(\s*#{k_v_s}[ \t]*)(.*)\s*$/
1717
@@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)(.*?[^\s#{k_v_s}])(\s*#{k_v_s}[ \t]*)(.*)\s*$/
1818

1919
@path = path

spec/acceptance/ini_setting_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,40 @@
7272
it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, /four = five\n\n\[one\]\ntwo = three/
7373
end
7474

75+
context '=> present for global and section (from previous blank value)' do
76+
before :all do
77+
if fact('osfamily') == 'Darwin'
78+
shell("echo \"four =[one]\ntwo =\" > #{tmpdir}/ini_setting.ini")
79+
else
80+
shell("echo -e \"four =\n[one]\ntwo =\" > #{tmpdir}/ini_setting.ini")
81+
end
82+
end
83+
84+
pp = <<-EOS
85+
ini_setting { 'ensure => present for section':
86+
ensure => present,
87+
path => "#{tmpdir}/ini_setting.ini",
88+
section => 'one',
89+
setting => 'two',
90+
value => 'three',
91+
}
92+
ini_setting { 'ensure => present for global':
93+
ensure => present,
94+
path => "#{tmpdir}/ini_setting.ini",
95+
section => '',
96+
setting => 'four',
97+
value => 'five',
98+
}
99+
EOS
100+
101+
it 'applies the manifest twice' do
102+
apply_manifest(pp, :catch_failures => true)
103+
apply_manifest(pp, :catch_changes => true)
104+
end
105+
106+
it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, /four = five\n\n\[one\]\ntwo = three/
107+
end
108+
75109
context '=> absent for key/value' do
76110
before :all do
77111
if fact('osfamily') == 'Darwin'

0 commit comments

Comments
 (0)