Skip to content

Commit

Permalink
support spaces in sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Newland committed Dec 2, 2013
1 parent 2b45293 commit c058ee5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/puppet/util/ini_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Puppet
module Util
class IniFile

@@SECTION_REGEX = /^\s*\[([\s\w\d\.\\\/\-\:]+)\]\s*$/
@@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*$/

Expand Down
52 changes: 52 additions & 0 deletions spec/unit/puppet/provider/ini_setting/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,58 @@ def self.file_path
end
end

context "when sections have spaces and dashes" do
let(:orig_content) {
<<-EOS
# This is a comment
[section - one]
; This is also a comment
foo=foovalue
bar = barvalue
master = true
[section - two]
foo= foovalue2
baz=bazvalue
url = http://192.168.1.1:8080
[section:sub]
subby=bar
#another comment
; yet another comment
EOS
}

it "should add a missing setting to the correct section" do
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => 'section - two', :setting => 'yahoo', :value => 'yippee'))
provider = described_class.new(resource)
provider.exists?.should be_nil
provider.create
validate_file(<<-EOS
# This is a comment
[section - one]
; This is also a comment
foo=foovalue
bar = barvalue
master = true
[section - two]
foo= foovalue2
baz=bazvalue
url = http://192.168.1.1:8080
yahoo = yippee
[section:sub]
subby=bar
#another comment
; yet another comment
EOS
)
end

end

end

end

0 comments on commit c058ee5

Please sign in to comment.