From cb85148d8fd3241ec5a12d77f0fe3534d783137f Mon Sep 17 00:00:00 2001 From: Huan Do Date: Mon, 8 Sep 2014 23:12:09 -0700 Subject: [PATCH 1/2] fix issue where single characters settings were not being saved. see https://github.com/boxen/puppet-git/issues/30 --- lib/puppet/util/ini_file.rb | 2 +- spec/unit/puppet/util/ini_file_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index 39775a5a..bc2ce540 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -6,7 +6,7 @@ module Util class IniFile @@SECTION_REGEX = /^\s*\[([^\]]*)\]\s*$/ - @@SETTING_REGEX = /^(\s*)([^\[#;][\w\d\.\\\/\-\s\[\]\']*[\w\d\.\\\/\-\]])([ \t]*=[ \t]*)([\S\s]*?)\s*$/ + @@SETTING_REGEX = /^(\s*)([\w\d\.\\\/\-\s\[\]\']*[\w\d\.\\\/\-\]])([ \t]*=[ \t]*)([\S\s]*?)\s*$/ @@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)([^\[]*[\w\d\.\\\/\-]+[\w\d\.\\\/\-\[\]\']+)([ \t]*=[ \t]*)([\S\s]*?)\s*$/ def initialize(path, key_val_separator = ' = ') diff --git a/spec/unit/puppet/util/ini_file_spec.rb b/spec/unit/puppet/util/ini_file_spec.rb index 8e8da9c8..b68fb09a 100644 --- a/spec/unit/puppet/util/ini_file_spec.rb +++ b/spec/unit/puppet/util/ini_file_spec.rb @@ -30,6 +30,7 @@ ; yet another comment zot = multi word value xyzzy['thing1']['thing2']=xyzzyvalue + l=git log EOS template.split("\n") } @@ -52,6 +53,7 @@ subject.get_value("section2", "baz").should == "bazvalue" subject.get_value("section2", "zot").should == "multi word value" subject.get_value("section2", "xyzzy['thing1']['thing2']").should == "xyzzyvalue" + subject.get_value("section2", "l").should == "git log" end end From 441577981df5801e11dd6e8d5061ae5b239ad88c Mon Sep 17 00:00:00 2001 From: Huan Do Date: Fri, 12 Sep 2014 16:55:24 -0700 Subject: [PATCH 2/2] modify test to compare to a hash which better tests the state of each setting also update @@COMMENTED_SETTING_REGEX to be roughly equal to "(\s*)[#;]+" + @@SETTING_REGEX --- lib/puppet/util/ini_file.rb | 2 +- spec/unit/puppet/util/ini_file_spec.rb | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index bc2ce540..a8d715c4 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -7,7 +7,7 @@ class IniFile @@SECTION_REGEX = /^\s*\[([^\]]*)\]\s*$/ @@SETTING_REGEX = /^(\s*)([\w\d\.\\\/\-\s\[\]\']*[\w\d\.\\\/\-\]])([ \t]*=[ \t]*)([\S\s]*?)\s*$/ - @@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)([^\[]*[\w\d\.\\\/\-]+[\w\d\.\\\/\-\[\]\']+)([ \t]*=[ \t]*)([\S\s]*?)\s*$/ + @@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)([\w\d\.\\\/\-\s\[\]\']*[\w\d\.\\\/\-\]])([ \t]*=[ \t]*)([\S\s]*?)\s*$/ def initialize(path, key_val_separator = ' = ') @path = path diff --git a/spec/unit/puppet/util/ini_file_spec.rb b/spec/unit/puppet/util/ini_file_spec.rb index b68fb09a..dca6dab2 100644 --- a/spec/unit/puppet/util/ini_file_spec.rb +++ b/spec/unit/puppet/util/ini_file_spec.rb @@ -26,6 +26,7 @@ foo= foovalue2 baz=bazvalue + ; commented = out setting #another comment ; yet another comment zot = multi word value @@ -46,14 +47,19 @@ end it "should expose settings for sections" do - subject.get_value("section1", "foo").should == "foovalue" - subject.get_value("section1", "bar").should == "barvalue" - subject.get_value("section1", "baz").should == "" - subject.get_value("section2", "foo").should == "foovalue2" - subject.get_value("section2", "baz").should == "bazvalue" - subject.get_value("section2", "zot").should == "multi word value" - subject.get_value("section2", "xyzzy['thing1']['thing2']").should == "xyzzyvalue" - subject.get_value("section2", "l").should == "git log" + subject.get_settings("section1").should == { + "bar" => "barvalue", + "baz" => "", + "foo" => "foovalue" + } + + subject.get_settings("section2").should == { + "baz" => "bazvalue", + "foo" => "foovalue2", + "l" => "git log", + "xyzzy['thing1']['thing2']" => "xyzzyvalue", + "zot" => "multi word value" + } end end