From 49960e1c5ebb6d05338ad653e53b273c17d1d915 Mon Sep 17 00:00:00 2001 From: Pete Johns Date: Thu, 26 Jun 2014 21:33:26 +1000 Subject: [PATCH] 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. --- lib/puppet/util/ini_file.rb | 2 +- spec/unit/puppet/util/ini_file_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index 72e9fca..39775a5 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -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*$/ diff --git a/spec/unit/puppet/util/ini_file_spec.rb b/spec/unit/puppet/util/ini_file_spec.rb index 0ebc354..8ace297 100644 --- a/spec/unit/puppet/util/ini_file_spec.rb +++ b/spec/unit/puppet/util/ini_file_spec.rb @@ -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