mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
PluginManager#load_cli_options: use the realpath (#1762)
* PluginManager#load_cli_options: use the realpath Since ruby 2.5, `require 'foo'` will use the realpath of the file corresponding to foo.rb. However `require '/absolute/path/to/foo.rb'` won't use the realpath. So when $GEM_HOME contains a symlink (ie it is not the realpath), when a pry plugin is loaded, by `activate!`: require gem_name if !active? the real_path of `gem_name` is used. But then in load_cli_options: cli_options_file = File.join(spec.full_gem_path, "lib/#{spec.name}/cli.rb") require cli_options_file if File.exist?(cli_options_file) since the path given is absolute, it will be used directly without realpath. This means that cli.rb may potentially be required twice (once via its realpath if the plugin requires it, the other via its $GEM_HOME path when required by `load_cli_options`), which could raise some errors. Fix this by using the realpath in load_cli_options too. Revision r59984 in ruby 2.5 introduced the use of realpath for load paths, and it was backported to version 2.4 in the minor revision 2.4.4. So only use the realpath ourselves for ruby versions above or equal to 2.4.4.
This commit is contained in:
parent
c180f2262d
commit
975fd746db
1 changed files with 1 additions and 0 deletions
|
@ -35,6 +35,7 @@ class Pry
|
|||
# Load the Command line options defined by this plugin (if they exist)
|
||||
def load_cli_options
|
||||
cli_options_file = File.join(spec.full_gem_path, "lib/#{spec.name}/cli.rb")
|
||||
cli_options_file = File.realpath(cli_options_file) if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4.4")
|
||||
require cli_options_file if File.exist?(cli_options_file)
|
||||
end
|
||||
# Activate the plugin (require the gem - enables/loads the
|
||||
|
|
Loading…
Reference in a new issue