summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStrech (Sergey Fedorov) <oni.strech@gmail.com>2015-05-14 14:02:14 +0500
committerAndre Arko <andre@arko.net>2015-05-16 14:40:18 -0700
commited86e50c8c7414c0a53f5288c5e4e7925b4960d5 (patch)
tree1b0be360183328c77112bfb1a27104d42eff3ad6
parent910529997449d91e94f1ce58dce59dc2212320e2 (diff)
downloadbundler-ed86e50c8c7414c0a53f5288c5e4e7925b4960d5.tar.gz
Added backward compatibility for BUNDLE_* config keys
Closes #3557
-rw-r--r--lib/bundler/settings.rb8
-rw-r--r--spec/bundler/settings_spec.rb18
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index a29e7104c7..88e139ccd1 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -178,7 +178,7 @@ module Bundler
config_regex = /^(BUNDLE_.+): (['"]?)(.*(?:\n(?!BUNDLE).+)?)\2$/
config_pairs = config_file.read.scan(config_regex).map do |m|
key, _, value = m
- [key, value.gsub(/\s+/, " ").tr('"', "'")]
+ [convert_to_backward_compatible_key(key), value.gsub(/\s+/, " ").tr('"', "'")]
end
Hash[config_pairs]
else
@@ -186,6 +186,12 @@ module Bundler
end
end
+ def convert_to_backward_compatible_key(key)
+ key = "#{key}/" if key =~ /https?:/i && key !~ %r[/\Z]
+ key = key.gsub(".", "__") if key.include?(".")
+ key
+ end
+
# TODO: duplicates Rubygems#normalize_uri
# TODO: is this the correct place to validate mirror URIs?
def normalize_uri(uri)
diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb
index 56ee87da6e..a6c6d42efa 100644
--- a/spec/bundler/settings_spec.rb
+++ b/spec/bundler/settings_spec.rb
@@ -48,6 +48,24 @@ describe Bundler::Settings do
settings["mirror.https://rubygems.org"] = "http://rubygems-mirror.org"
expect(settings.gem_mirrors).to eq(URI("https://rubygems.org/") => URI("http://rubygems-mirror.org/"))
end
+ end
+
+ describe "BUNDLE_ keys format" do
+ let(:settings) { described_class.new(bundled_app('.bundle')) }
+
+ it "converts older keys without double dashes" do
+ config("BUNDLE_MY__PERSONAL.RACK" => "~/Work/git/rack")
+ expect(settings["my.personal.rack"]).to eq("~/Work/git/rack")
+ end
+ it "converts older keys without trailing slashes and double dashes" do
+ config("BUNDLE_MIRROR__HTTPS://RUBYGEMS.ORG" => "http://rubygems-mirror.org")
+ expect(settings["mirror.https://rubygems.org/"]).to eq("http://rubygems-mirror.org")
+ end
+
+ it "reads newer keys format properly" do
+ config("BUNDLE_MIRROR__HTTPS://RUBYGEMS__ORG/" => "http://rubygems-mirror.org")
+ expect(settings["mirror.https://rubygems.org/"]).to eq("http://rubygems-mirror.org")
+ end
end
end