diff options
Diffstat (limited to 'lib/rubygems/path_support.rb')
| -rw-r--r-- | lib/rubygems/path_support.rb | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb index 618bc793c4..13091e29ba 100644 --- a/lib/rubygems/path_support.rb +++ b/lib/rubygems/path_support.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ## # # Gem::PathSupport facilitates the GEM_HOME and GEM_PATH environment settings @@ -23,25 +24,26 @@ class Gem::PathSupport # hashtable, or defaults to ENV, the system environment. # def initialize(env) - @home = env["GEM_HOME"] || Gem.default_dir - - if File::ALT_SEPARATOR then - @home = @home.gsub(File::ALT_SEPARATOR, File::SEPARATOR) - end - + @home = normalize_home_dir(env["GEM_HOME"] || Gem.default_dir) @path = split_gem_path env["GEM_PATH"], @home @spec_cache_dir = env["GEM_SPEC_CACHE"] || Gem.default_spec_cache_dir - - @spec_cache_dir = @spec_cache_dir.dup.untaint end private + def normalize_home_dir(home) + if File::ALT_SEPARATOR + home = home.gsub(File::ALT_SEPARATOR, File::SEPARATOR) + end + + expand(home) + end + ## # Split the Gem search path (as reported by Gem.path). - def split_gem_path gpaths, home + def split_gem_path(gpaths, home) # FIX: it should be [home, *path], not [*path, home] gem_path = [] @@ -50,11 +52,11 @@ class Gem::PathSupport gem_path = gpaths.split(Gem.path_separator) # Handle the path_separator being set to a regexp, which will cause # end_with? to error - if gpaths =~ /#{Gem.path_separator}\z/ + if /#{Gem.path_separator}\z/.match?(gpaths) gem_path += default_path end - if File::ALT_SEPARATOR then + if File::ALT_SEPARATOR gem_path.map! do |this_path| this_path.gsub File::ALT_SEPARATOR, File::SEPARATOR end @@ -65,16 +67,19 @@ class Gem::PathSupport gem_path = default_path end - gem_path.uniq + gem_path.map {|path| expand(path) }.uniq end # Return the default Gem path def default_path - gem_path = Gem.default_path + [@home] + Gem.default_path + [@home] + end - if defined?(APPLE_GEM_HOME) - gem_path << APPLE_GEM_HOME + def expand(path) + if File.directory?(path) + File.realpath(path) + else + path end - gem_path end end |
