Skip to content

Commit a747f66

Browse files
Michael Siroskeybmjen
authored andcommitted
Fixed SETTING_REGEX and COMMENTED_SETTING_REGEX to allow spaces in setting names.
1 parent 70c7fb2 commit a747f66

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

lib/puppet/util/ini_file.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ def initialize(path, key_val_separator = ' = ')
1010
k_v_s = key_val_separator.strip
1111

1212
@@SECTION_REGEX = /^\s*\[([^\]]*)\]\s*$/
13-
@@SETTING_REGEX = /^(\s*)([^\s#{k_v_s}]*)(\s*#{k_v_s}\s*)(.*)\s*$/
14-
@@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)([^\s#{k_v_s}]*)(\s*#{k_v_s}[ \t]*)(.*)\s*$/
15-
13+
@@SETTING_REGEX = /^(\s*)([^#;\s]|[^#;\s].*?[^\s#{k_v_s}])(\s*#{k_v_s}\s*)(.*)\s*$/
14+
@@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)(.*?[^\s#{k_v_s}])(\s*#{k_v_s}[ \t]*)(.*)\s*$/
1615

1716
@path = path
1817
@key_val_separator = key_val_separator

spec/unit/puppet/util/ini_file_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,25 @@
262262
subject.get_value("Drive names", "C:").should eq 'Winchester'
263263
end
264264
end
265+
context 'Configuration with spaces in setting names' do
266+
let(:sample_content) do
267+
template = <<-EOS
268+
[global]
269+
# log files split per-machine:
270+
log file = /var/log/samba/log.%m
271+
272+
kerberos method = system keytab
273+
passdb backend = tdbsam
274+
security = ads
275+
EOS
276+
template.split("\n")
277+
end
278+
279+
it "should expose settings for sections" do
280+
subject.get_value("global", "log file").should eq '/var/log/samba/log.%m'
281+
subject.get_value("global", "kerberos method").should eq 'system keytab'
282+
subject.get_value("global", "passdb backend").should eq 'tdbsam'
283+
subject.get_value("global", "security").should eq 'ads'
284+
end
285+
end
265286
end

0 commit comments

Comments
 (0)