Skip to content

Commit

Permalink
Merge pull request redhat-openstack#65 from shrug/master
Browse files Browse the repository at this point in the history
Update settings regexes to support settings containing square brackets
  • Loading branch information
hunner committed Dec 6, 2013
2 parents ae23a4d + 76ad4c4 commit a0b63eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/puppet/util/ini_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module Util
class IniFile

@@SECTION_REGEX = /^\s*\[([\w\d\.\\\/\-\:\s]*[\w\d\.\\\/\-])\]\s*$/
@@SETTING_REGEX = /^(\s*)([\w\d\.\\\/\-\s]*[\w\d\.\\\/\-])([ \t]*=[ \t]*)([\S\s]*?)\s*$/
@@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\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 = ' = ')
@path = path
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/puppet/util/ini_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#another comment
; yet another comment
zot = multi word value
xyzzy['thing1']['thing2']=xyzzyvalue
EOS
template.split("\n")
}
Expand All @@ -50,6 +51,7 @@
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"
end

end
Expand Down Expand Up @@ -113,6 +115,7 @@
[section1]
foo=
#bar=
#xyzzy['thing1']['thing2']='xyzzyvalue'
EOS
template.split("\n")
}
Expand All @@ -127,6 +130,9 @@
subject.get_value("section1", "bar").should == nil
subject.set_value("section1", "bar", "barvalue")
subject.get_value("section1", "bar").should == "barvalue"
subject.get_value("section1", "xyzzy['thing1']['thing2']").should == nil
subject.set_value("section1", "xyzzy['thing1']['thing2']", "xyzzyvalue")
subject.get_value("section1", "xyzzy['thing1']['thing2']").should == "xyzzyvalue"
end

it "should properly add new empty values" do
Expand Down

0 comments on commit a0b63eb

Please sign in to comment.