summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-04-18 07:31:47 +0900
committerHomu <homu@barosl.com>2016-04-18 07:31:47 +0900
commit0446fa9860f36a3ee75fa12599e03fabc613a894 (patch)
tree4c39eb26caaee241b188e73ef58d7bfee9fda0fe
parentf401c17292c67b94b0f15a8c40af528fbb243f37 (diff)
parent4d2e7117f3136003256baf49d95001e7e784c078 (diff)
downloadbundler-0446fa9860f36a3ee75fa12599e03fabc613a894.tar.gz
Auto merge of #4410 - bundler:seg-settings-load-config-tests, r=segiddins
Improve loading config files Closes #4370.
-rw-r--r--lib/bundler/settings.rb17
-rw-r--r--spec/bundler/settings_spec.rb37
2 files changed, 52 insertions, 2 deletions
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index 175c9a76db..8e43918097 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -221,12 +221,25 @@ module Bundler
Pathname.new(@root).join("config") if @root
end
+ CONFIG_REGEX = %r{ # rubocop:disable Style/RegexpLiteral
+ ^
+ (BUNDLE_.+):\s # the key
+ (?: !\s)? # optional exclamation mark found with ruby 1.9.3
+ (['"]?) # optional opening quote
+ (.* # contents of the value
+ (?: # optionally, up until the next key
+ (\n(?!BUNDLE).+)*
+ )
+ )
+ \2 # matching closing quote
+ $
+ }xo
+
def load_config(config_file)
SharedHelpers.filesystem_access(config_file, :read) do
valid_file = config_file && config_file.exist? && !config_file.size.zero?
return {} if ignore_config? || !valid_file
- config_regex = /^(BUNDLE_.+): (['"]?)(.*(?:\n(?!BUNDLE).+)?)\2$/
- config_pairs = config_file.read.scan(config_regex).map do |m|
+ config_pairs = config_file.read.scan(CONFIG_REGEX).map do |m|
key, _, value = m
[convert_to_backward_compatible_key(key), value.gsub(/\s+/, " ").tr('"', "'")]
end
diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb
index 239f5e6ade..a4ac02c0fb 100644
--- a/spec/bundler/settings_spec.rb
+++ b/spec/bundler/settings_spec.rb
@@ -16,6 +16,43 @@ describe Bundler::Settings do
end
end
+ describe "load_config" do
+ let(:hash) do
+ {
+ "build.thrift" => "--with-cppflags=-D_FORTIFY_SOURCE=0",
+ "build.libv8" => "--with-system-v8",
+ "build.therubyracer" => "--with-v8-dir",
+ "build.pg" => "--with-pg-config=/usr/local/Cellar/postgresql92/9.2.8_1/bin/pg_config",
+ "gem.coc" => "false",
+ "gem.mit" => "false",
+ "gem.test" => "minitest",
+ "thingy" => <<-EOS.tr("\n", " "),
+--asdf --fdsa --ty=oh man i hope this doesnt break bundler because
+that would suck --ehhh=oh geez it looks like i might have broken bundler somehow
+--very-important-option=DontDeleteRoo
+--very-important-option=DontDeleteRoo
+--very-important-option=DontDeleteRoo
+--very-important-option=DontDeleteRoo
+ EOS
+ "xyz" => "zyx",
+ }
+ end
+
+ before do
+ hash.each do |key, value|
+ settings[key] = value
+ end
+ end
+
+ it "can load the config" do
+ loaded = settings.send(:load_config, bundled_app("config"))
+ expected = Hash[hash.map do |k, v|
+ [settings.send(:key_for, k), v.to_s]
+ end]
+ expect(loaded).to eq(expected)
+ end
+ end
+
describe "#[]" do
context "when not set" do
context "when default value present" do