Skip to content

Commit 49960e1

Browse files
committed
Handle quotation marks in section names
The section name appears on a line by itself, in square brackets (`[` and `]`), all characters between the opening `[` and the closing `]` should be considered to form the section name.
1 parent 41fc8bf commit 49960e1

2 files changed

Lines changed: 26 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
@@ -5,7 +5,7 @@ module Puppet
55
module Util
66
class IniFile
77

8-
@@SECTION_REGEX = /^\s*\[([\w\d\.\\\/\-\:\s]*[\w\d\.\\\/\-])\]\s*$/
8+
@@SECTION_REGEX = /^\s*\[([^\]]*)\]\s*$/
99
@@SETTING_REGEX = /^(\s*)([^\[#;][\w\d\.\\\/\-\s\[\]\']*[\w\d\.\\\/\-\]])([ \t]*=[ \t]*)([\S\s]*?)\s*$/
1010
@@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)([^\[]*[\w\d\.\\\/\-]+[\w\d\.\\\/\-\[\]\']+)([ \t]*=[ \t]*)([\S\s]*?)\s*$/
1111

spec/unit/puppet/util/ini_file_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,29 @@
141141
subject.get_value("section1", "baz").should == "bazvalue"
142142
end
143143
end
144+
145+
context 'the file has quotation marks in its section names' do
146+
let(:sample_content) do
147+
template = <<-EOS
148+
[branch "master"]
149+
remote = origin
150+
merge = refs/heads/master
151+
152+
[alias]
153+
to-deploy = log --merges --grep='pull request' --format='%s (%cN)' origin/production..origin/master
154+
[branch "production"]
155+
remote = origin
156+
merge = refs/heads/production
157+
EOS
158+
template.split("\n")
159+
end
160+
161+
it 'should parse the sections' do
162+
subject.section_names.should match_array ['',
163+
'branch "master"',
164+
'alias',
165+
'branch "production"'
166+
]
167+
end
168+
end
144169
end

0 commit comments

Comments
 (0)