From 79a17d5c22064faeeb1d9ae5fe00463e18370dd3 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 9 Mar 2015 12:15:10 +1100 Subject: [PATCH] FIX: discourse.conf not parsing out comments correctly --- app/models/global_setting.rb | 2 +- spec/models/global_setting_spec.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb index 6f3581d81..08bd5cafc 100644 --- a/app/models/global_setting.rb +++ b/app/models/global_setting.rb @@ -66,7 +66,7 @@ class GlobalSetting def read ERB.new(File.read(@file)).result().split("\n").each do |line| - if line =~ /([a-z_]+)\s*=\s*(\"([^\"]*)\"|\'([^\']*)\'|[^#]*)/ + if line =~ /^\s*([a-z_]+)\s*=\s*(\"([^\"]*)\"|\'([^\']*)\'|[^#]*)/ @data[$1.strip.to_sym] = ($4 || $3 || $2).strip end end diff --git a/spec/models/global_setting_spec.rb b/spec/models/global_setting_spec.rb index 06a604dd7..e371b15d6 100644 --- a/spec/models/global_setting_spec.rb +++ b/spec/models/global_setting_spec.rb @@ -12,10 +12,11 @@ describe GlobalSetting::FileProvider do f = Tempfile.new('foo') f.write(" # this is a comment\n") f.write("\n") - f.write("a = 1000 # this is a comment\n") + f.write(" a = 1000 # this is a comment\n") f.write("b = \"10 # = 00\" # this is a # comment\n") f.write("c = \'10 # = 00\' # this is a # comment\n") f.write("d =\n") + f.write("#f = 1\n") f.close provider = GlobalSetting::FileProvider.from(f.path) @@ -25,6 +26,7 @@ describe GlobalSetting::FileProvider do expect(provider.lookup(:c,"")).to eq "10 # = 00" expect(provider.lookup(:d,"bob")).to eq nil expect(provider.lookup(:e,"bob")).to eq "bob" + expect(provider.lookup(:f,"bob")).to eq "bob" expect(provider.keys.sort).to eq [:a, :b, :c, :d]