summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-03-28 17:46:16 -0500
committerSamuel Giddins <segiddins@segiddins.me>2016-03-28 17:46:16 -0500
commit4fe19816b28f0ddb0b933a8e9b102284fdb258fe (patch)
treeaf55a966bad44a38b963d408cf71403db1c8736c
parentd716a0ada398f53cd0ecf5e1708d10426e3833eb (diff)
downloadbundler-4fe19816b28f0ddb0b933a8e9b102284fdb258fe.tar.gz
[Settings] Use an improved regexp to read config file
This will improve support for long values that get split across multiple lines. h/t to @jbodah for coming up with the crux of the changes
-rw-r--r--lib/bundler/settings.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index 175c9a76db..2eaf426fbb 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -221,12 +221,24 @@ module Bundler
Pathname.new(@root).join("config") if @root
end
+ CONFIG_REGEX = %r{ # rubocop:disable Style/RegexpLiteral
+ ^
+ (BUNDLE_.+):\s # the key
+ (['"]?) # 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