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.
This commit is contained in:
Pete Johns 2014-06-26 21:33:26 +10:00
parent 41fc8bfbf5
commit 49960e1c5e
2 changed files with 26 additions and 1 deletions

View file

@ -5,7 +5,7 @@ module Puppet
module Util
class IniFile
@@SECTION_REGEX = /^\s*\[([\w\d\.\\\/\-\:\s]*[\w\d\.\\\/\-])\]\s*$/
@@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*$/

View file

@ -141,4 +141,29 @@ foo=
subject.get_value("section1", "baz").should == "bazvalue"
end
end
context 'the file has quotation marks in its section names' do
let(:sample_content) do
template = <<-EOS
[branch "master"]
remote = origin
merge = refs/heads/master
[alias]
to-deploy = log --merges --grep='pull request' --format='%s (%cN)' origin/production..origin/master
[branch "production"]
remote = origin
merge = refs/heads/production
EOS
template.split("\n")
end
it 'should parse the sections' do
subject.section_names.should match_array ['',
'branch "master"',
'alias',
'branch "production"'
]
end
end
end