From c784253096727b2c3e30de11cca5ccbd022e72f3 Mon Sep 17 00:00:00 2001 From: Mike Dorman Date: Thu, 18 Jun 2015 15:06:44 -0600 Subject: [PATCH] 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. --- lib/puppet/util/ini_file.rb | 2 +- spec/acceptance/ini_setting_spec.rb | 34 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index e67e5b5d0..857b12dc4 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -13,7 +13,7 @@ def initialize(path, key_val_separator = ' = ', section_prefix = '[', section_su @section_suffix = section_suffix @@SECTION_REGEX = section_regex - @@SETTING_REGEX = /^(\s*)([^#;\s]|[^#;\s].*?[^\s#{k_v_s}])(\s*#{k_v_s}\s*)(.*)\s*$/ + @@SETTING_REGEX = /^(\s*)([^#;\s]|[^#;\s].*?[^\s#{k_v_s}])(\s*#{k_v_s}[ \t]*)(.*)\s*$/ @@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)(.*?[^\s#{k_v_s}])(\s*#{k_v_s}[ \t]*)(.*)\s*$/ @path = path diff --git a/spec/acceptance/ini_setting_spec.rb b/spec/acceptance/ini_setting_spec.rb index b7e2b6a79..1a829db89 100644 --- a/spec/acceptance/ini_setting_spec.rb +++ b/spec/acceptance/ini_setting_spec.rb @@ -72,6 +72,40 @@ it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, /four = five\n\n\[one\]\ntwo = three/ end + context '=> present for global and section (from previous blank value)' do + before :all do + if fact('osfamily') == 'Darwin' + shell("echo \"four =[one]\ntwo =\" > #{tmpdir}/ini_setting.ini") + else + shell("echo -e \"four =\n[one]\ntwo =\" > #{tmpdir}/ini_setting.ini") + end + end + + pp = <<-EOS + ini_setting { 'ensure => present for section': + ensure => present, + path => "#{tmpdir}/ini_setting.ini", + section => 'one', + setting => 'two', + value => 'three', + } + ini_setting { 'ensure => present for global': + ensure => present, + path => "#{tmpdir}/ini_setting.ini", + section => '', + setting => 'four', + value => 'five', + } + EOS + + it 'applies the manifest twice' do + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, /four = five\n\n\[one\]\ntwo = three/ + end + context '=> absent for key/value' do before :all do if fact('osfamily') == 'Darwin'