Skip to content

bcrypt may append invalid paths to $LOAD_PATH  #6

@josh

Description

@josh

I've been using some of the "alternative" ruby package mangers that copy files out of the original directory similar to setup.rb's approach. It doesn't seem to be causing a huge deal, but bcrypt-ruby tries to reference ext/ which is outside lib/. It should be possible to just require 'bcrypt_ext' without modifying the load path. Even with rubygems, ext/bcrypt_ext.* will be copied into lib/bcrypt_ext.* when you "gem install bcrypt-ruby". (I'm unfamiliar with jruby's extension conventions though)

A low impact change would be to check if the ext/ directory exists before adding it to the load path. The better fix imo is to have "rake compile" copy the file into lib and remove the load path manipulation. This mimics package installer behavior more closely. Its your lib, your call.

diff --git a/lib/bcrypt.rb b/lib/bcrypt.rb
index 7776829..3490e14 100644
--- a/lib/bcrypt.rb
+++ b/lib/bcrypt.rb
@@ -4,7 +4,8 @@ if RUBY_PLATFORM == "java"
   require 'java'
   $CLASSPATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "ext", "jruby"))
 else
-  $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "ext", "mri")))
+  extdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "ext", "mri"))
+  $LOAD_PATH.unshift(extdir) if File.directory?(extdir) && !$LOAD_PATH.include?(extdir)
   require "bcrypt_ext"
   require "openssl"
 end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions